caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Comment syntax?
@ 2016-09-14 12:34 Tom Ridge
  2016-09-14 12:38 ` David Allsopp
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Ridge @ 2016-09-14 12:34 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 197 bytes --]

Dear All,

My opam install of ocaml 4.03.1 seems to compile the following:

(* " *)
is this ml?
(* " *)

Presumably the parser thinks the comment extends from l.1 to l.3

Is this intended?

Thanks

[-- Attachment #2: Type: text/html, Size: 382 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [Caml-list] Comment syntax?
  2016-09-14 12:34 [Caml-list] Comment syntax? Tom Ridge
@ 2016-09-14 12:38 ` David Allsopp
  2016-09-14 12:51   ` Tom Ridge
  0 siblings, 1 reply; 5+ messages in thread
From: David Allsopp @ 2016-09-14 12:38 UTC (permalink / raw)
  To: Tom Ridge, caml-list

Tom Ridge wrote:
> My opam install of ocaml 4.03.1 seems to compile the following:
> 
> (* " *)
> 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Comment syntax?
  2016-09-14 12:38 ` David Allsopp
@ 2016-09-14 12:51   ` Tom Ridge
  2016-09-14 13:04     ` Jeremy Yallop
  2016-09-14 13:11     ` David Allsopp
  0 siblings, 2 replies; 5+ messages in thread
From: Tom Ridge @ 2016-09-14 12:51 UTC (permalink / raw)
  To: David Allsopp; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1220 bytes --]

Isn't this rather complicated?

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).

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.

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?

Thanks



On 14 September 2016 at 13:38, David Allsopp <dra-news@metastack.com> wrote:

> Tom Ridge wrote:
> > My opam install of ocaml 4.03.1 seems to compile the following:
> >
> > (* " *)
> > 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
>
>

[-- Attachment #2: Type: text/html, Size: 1904 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Comment syntax?
  2016-09-14 12:51   ` Tom Ridge
@ 2016-09-14 13:04     ` Jeremy Yallop
  2016-09-14 13:11     ` David Allsopp
  1 sibling, 0 replies; 5+ messages in thread
From: Jeremy Yallop @ 2016-09-14 13:04 UTC (permalink / raw)
  To: Tom Ridge; +Cc: David Allsopp, caml-list

On 14 September 2016 at 13:51, Tom Ridge
<tom.j.ridge+list@googlemail.com> wrote:
> 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'.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [Caml-list] Comment syntax?
  2016-09-14 12:51   ` Tom Ridge
  2016-09-14 13:04     ` Jeremy Yallop
@ 2016-09-14 13:11     ` David Allsopp
  1 sibling, 0 replies; 5+ messages in thread
From: David Allsopp @ 2016-09-14 13:11 UTC (permalink / raw)
  To: Tom Ridge; +Cc: caml-list

Tom Ridge wrote:
> 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...) 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-09-14 13:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-14 12:34 [Caml-list] Comment syntax? Tom Ridge
2016-09-14 12:38 ` David Allsopp
2016-09-14 12:51   ` Tom Ridge
2016-09-14 13:04     ` Jeremy Yallop
2016-09-14 13:11     ` David Allsopp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).