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

Multiple semicolons at the end of a line with no error mentioned #7727

Closed
vicuna opened this issue Feb 16, 2018 · 7 comments
Closed

Multiple semicolons at the end of a line with no error mentioned #7727

vicuna opened this issue Feb 16, 2018 · 7 comments

Comments

@vicuna
Copy link

vicuna commented Feb 16, 2018

Original bug ID: 7727
Reporter: vanto
Status: resolved (set by @xavierleroy on 2018-02-17T16:46:17Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 4.06.0
Category: toplevel
Has duplicate: #7728
Monitored by: @gasche

Bug description

Toplevel system 4.06. Reference manual 4.06 page 213.
It is written "A line is terminated by ;; (a double-semicolon)."
But we notice that we can write several semicolons at the end of a line and get the result without an error notification.
We can write several lines ending with several semicolons, there will never be any error mentioned.
Below, example in OCaml 4.06:

"zs";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;

  • : string = "zs"

45;;;

  • : int = 45

89;;;

  • : int = 89

1234;;;;

  • : int = 1234

it seems that this continues since Caml Light release 0.74, except
that Caml Light only accepts three semicolons (;;;) without error.
But in the next line if we write another line, even correct, the error
is this time mentioned.
Below, example in Caml Light:
#"aa";;

  • : string = "aa"
    #"bb";;;
  • : string = "bb"
    #"cc";;
    Entrée interactive:

"bb";;;
^
Erreur de syntaxe.

@vicuna
Copy link
Author

vicuna commented Feb 16, 2018

Comment author: @Octachron

This might warrant a clarification, but the current rule is that toplevel phrase are terminated by ";;"; and whatever comes after does not matter. In other words, if you are in a particularly interrogative mood, you can end your toplevel phrase with

() ;; ???

@vicuna
Copy link
Author

vicuna commented Feb 17, 2018

Comment author: vanto

Yes, this needs to be clarified. If this example above is calculated in Caml Light, the answer is:
#();;???

  • : unit = ()
    there is no error. On the other hand if I write this other example in Caml Light then there is an error which is:
    #"er";;???
    Entrée interactive:

....???
.........
L'identificateur ??? n'est pas défini.

It seems that the sequence of characters, after the double-semicolon, is taken into account by OCaml and this generates a loss of time and unnecessary calculation. I think it's better to stop writing after a double semicolon at the end of a line in the Toplevel. Are you sure it does not matter?

@vicuna
Copy link
Author

vicuna commented Feb 17, 2018

Comment author: @Octachron

Caml Light is obsolete and its quirks are not the object of this issue tracker.

The behavior of OCaml's toplevel is consistent (and utop is available as a more user-friendly version of the toplevel).

@vicuna
Copy link
Author

vicuna commented Feb 17, 2018

Comment author: vanto

Caml light is quoted here for comparison and I think we had another approach to programming over thirty years ago. I think you are wrong and this little problem deserves our full attention. Here utop has nothing to do.

@vicuna
Copy link
Author

vicuna commented Feb 17, 2018

Comment author: @Octachron

A Github PR clarifying the behavior of the interactive mode would be welcome if you think that this behavior deserves your full attention.

@vicuna
Copy link
Author

vicuna commented Feb 17, 2018

Comment author: @xavierleroy

There are two orthogonal points here:

1- In OCaml, ";;" without anything before is parsed as a "do nothing" toplevel phrase. This works both in separate compilation (ocamlc, ocamlopt) and in interactive use (ocaml).

2- In interactive use only (ocaml), the rest of the line after the terminating ";;" is ignored.

Both 1- and 2-, and especially 2-, are tolerances: they cause no harm, and might possibly be useful (?), but could also go away at any time, so we're not going to document them. Just don't use those tolerances and you'll be safe.

@vicuna vicuna closed this as completed Feb 17, 2018
@vicuna
Copy link
Author

vicuna commented Feb 18, 2018

Comment author: @gasche

The ability to enter an unattached attribute in the toplevel

[@@@foo];;

is useful (it can affect the state of a ppx transformation pass) and can be understood as an empty phrase (annotated).

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

No branches or pull requests

1 participant