Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

line comments delimiter #37

Open
const-rs opened this issue Mar 6, 2018 · 5 comments
Open

line comments delimiter #37

const-rs opened this issue Mar 6, 2018 · 5 comments

Comments

@const-rs
Copy link

const-rs commented Mar 6, 2018

Following the recent ideas in (ocaml pull-request discussion)[https://github.com/ocaml/ocaml/pull/671], I would like to propose another symbol for line comments - |*, since (*) conflicts with typical documentation generation tool like ocamldoc/haddock/doxygen.

Pro:

  1. |* is easy to extend for smldoc - |**.
  2. It is asymmetric, two character.
  3. Stylistically it is close to (* comment *); the opening symbol | does not have a pair like [ or (; blocks of comments are naturally separated by vertical line from code:
fun f x = 8 +  |* intercept term
    (sin x) +  |* sin component
    (cos x) +  |* cos component
    (sqrt x)   |* this works only for x >= 0
  1. It gives the same benefits as (* *) when commenting parts of the code. You need to add just one symbol to the right of pattern-matching or sum type declaration:
(* here we temporary comment out cos x with just two '*' *)
fun f x = 1.0 (*cos x*) 

datatype option a' = None
      | Some a'
      |* Unsure (* may be we will need this in the future? *)

Contra:

  1. (*) is already in proposal.
  2. |* is relatively hard to type compared to --, // or other common symbols.
@rossberg
Copy link
Member

rossberg commented Mar 6, 2018

I came up with (*) originally because it was the only syntax I could think of that is backwards-compatible. In contrast, |* is a valid symbolic identifier today, so repurposing it is a breaking change. The same applies to pretty much any combination of symbols or symbols+brackets you can think of. The only reason (*) works is because (* already has special status.

@ratmice
Copy link
Contributor

ratmice commented Mar 6, 2018

I really like ;; that was proposed in the linked thread (well i guess they proposed 3 semicolons),
2 was used in @rossberg 's 1ml, and the variant ;;;; comment to EOF, the only change there that I would consider is having ;;;; be whitespace significant so:

signature FOO = sig
;;;;
comment out stuff at the same indentation level, primarily useful for temporarily commenting
out code temporarily, like signature members
end
;;;; implicitly comment to EOF because we cannot indent lower than the beginning of the line.

I guess the issue is that the following is effectively allowed by existing compilers?
I will note that I don't see where in the grammar it is accepted, everything i saw treats semicolon as a sequence separator.

- val foo = 1;; val foo = 2;
val foo = 1 : int
val foo = 2 : int

@rossberg
Copy link
Member

rossberg commented Mar 6, 2018

Semicolon is a declaration separator in SML, and for better or worse, declarations can be empty. So ;; is a legal program today, as is any other number of consecutive semicolons.

@ratmice
Copy link
Contributor

ratmice commented Mar 6, 2018

@rossberg Thank you, I see it now, it took me quite a bit of staring before I noticed the empty declaration comment in figure 4/page 25, perhaps an empty optional <> on the left hand side would make it stand out more.

@JohnReppy
Copy link
Contributor

Another argument against changing is that MLton and SML/NJ already implement the "(*)" syntax (not enabled by default though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants