Discussion:
[Caml-list] Comment syntax?
(too old to reply)
David Allsopp
2016-09-14 12:38:35 UTC
Permalink
(* " *)
is this ml?
(* " *)
Presumably the parser thinks the comment extends from l.1 to l.3
Correct.
Is this intended?
Yes - string literals are parsed in comments. Brackets, quotes, etc. need to match. Weird as that can seem at first encounter, it permits arbitrary commenting out of blocks of code, which is quite useful...


David
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
Jeremy Yallop
2016-09-14 13:04:20 UTC
Permalink
On 14 September 2016 at 13:51, Tom Ridge
In this case, has there been any progress on "single line" comments
Yes: there's a recent concrete proposal, and a few (mostly multi-line)
comments on it here:

https://github.com/ocaml/ocaml/pull/671
// some comment
That would be backwards-incompatible, unfortunately. For example, the
following program

let f (
//
) = (
//
)

currently defines f as the polymorphic identity function, but with the
addition of '//' comments it would instead define a function of type
'unit -> unit'.
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
David Allsopp
2016-09-14 13:11:27 UTC
Permalink
Isn't this rather complicated? 
Complicated? It's a trade-off, sure. Very occasionally (usually when writing comments about parsers) one is forced to insert an unexpected symbol into a comment in order to satisfy the parser.
In this case, has there been any progress on "single line" comments eg 
// some comment
? I think this was mentioned recently on the list.
(I am also aware that // is verboten for some reason).
// is "verboten" because it is already available as an operator, so using it as a comment would break existing code.
It seems to me that multiline comments are a poor design choice. Single line
comments permit commenting arbitrary blocks (just prepend each line with
"//"), and play well with nested comments (no problem if a line starts
"// //" etc). Also, they are very simple to implement in the lexer.
A nice feature of nestable multiline comments which you don't get with only single-line comments is that you do actually know where the end of the commented block is. The fact OCaml uses a bracket even means you get matching without any extra support in editors (% in Vim, etc.) :o)
Please can we have support for simple (ie from the token "//" to the end-of-
line, no messing with string literals etc) single line comments?
https://github.com/ocaml/ocaml/pull/671

I'm not sure I agree that having multiline comments is a poor design choice, but I agree it would (very occasionally) be nice to have single-line comments as well.


David

(PS While I don't believe that all top-posting is evil, these threads read back better in archives when bottom-posted...)
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
Loading...