Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007727OCamltoplevelpublic2018-02-16 22:572018-02-18 08:01
Assigned To 
StatusresolvedResolutionno change required 
PlatformOSOS Version
Product Version4.06.0 
Target VersionFixed in Version 
Summary0007727: Multiple semicolons at the end of a line with no error mentioned
DescriptionToplevel 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:
- : string = "aa"
- : string = "bb"
Entrée interactive:
> ^
Erreur de syntaxe.
TagsNo tags attached.
Attached Files

- Relationships
has duplicate 0007728resolved this time strange compiler behavior in separate compilation with several semicolons and characters after 

-  Notes
octachron (developer)
2018-02-16 23:27
edited on: 2018-02-16 23:28

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

() ;; ???

vanto (viewer)
2018-02-17 14:21

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:
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?
octachron (developer)
2018-02-17 14:33

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).
vanto (viewer)
2018-02-17 14:48

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.
octachron (developer)
2018-02-17 15:05

A Github PR clarifying the behavior of the interactive mode would be welcome if you think that this behavior deserves your full attention.
xleroy (administrator)
2018-02-17 17:46

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.
gasche (developer)
2018-02-18 08:01

The ability to enter an unattached attribute in the toplevel


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

- Issue History
Date Modified Username Field Change
2018-02-16 22:57 vanto New Issue
2018-02-16 23:27 octachron Note Added: 0018875
2018-02-16 23:28 octachron Note Edited: 0018875 View Revisions
2018-02-17 14:21 vanto Note Added: 0018876
2018-02-17 14:33 octachron Note Added: 0018877
2018-02-17 14:48 vanto Note Added: 0018878
2018-02-17 15:05 octachron Note Added: 0018879
2018-02-17 17:46 xleroy Note Added: 0018880
2018-02-17 17:46 xleroy Status new => resolved
2018-02-17 17:46 xleroy Resolution open => no change required
2018-02-17 19:13 xleroy Relationship added has duplicate 0007728
2018-02-18 08:01 gasche Note Added: 0018885

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker