You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 3124 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
I went back through the manual and really couldn't find anything which
explained the difference between ; and ;;
The single ; is (usually) left associative binary sequencing
operator of type unit that takes two expressions of
type unit as an argument:
e1 ; e2
evaluates e1, then e2 (for side effects).
I said 'usually' because it has another role
in some contexts -- [();()] is a list of two
units whereas [(();())] is a list of one unit.
[This is like the ugly C hackery with , ]
The top level of Ocaml 'executes' statements in sequence.
For example:
let _ = e1
let _ = e2
The role of ;; has nothing to so with top level sequencing:
the sequencing is already built in.
The purpose of ;; is much simpler -- it is nothing
more than a piece of punctuation marking the end
of a statement.
As you can see above it is not required if
(a) there is a next statement and
(b) that next statement starts with a keyword
You may need ;; in the interpreter to tell it
'there isn't another statement, start evaluating'.
You may also need it if you use a statement
not starting with a keyword, for example here:
let x = ref 0
;; x := 1 (* doesn't start with a keyword *)
where you can see that ;; is more or less the keyword
you use to start a statement when it doesn't start
with a keyword.. that isn't quite correct, since you
don't need one at the start (its really a separator
which is 'infered' when the parser hits an unexpected
keyword :)
This code is actually very ugly because you can't
lift it out of the top level.
let _ =
let x = ref 0 in
x := 1
is the way to do this properly -- and here the x := 1
is an expression contained in the let/in expression.
Original bug ID: 3124
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
On Mon, 2004-08-30 at 17:12, Florian Hars wrote:
The single ; is (usually) left associative binary sequencing
operator of type unit that takes two expressions of
type unit as an argument:
evaluates e1, then e2 (for side effects).
I said 'usually' because it has another role
in some contexts -- [();()] is a list of two
units whereas [(();())] is a list of one unit.
[This is like the ugly C hackery with , ]
The top level of Ocaml 'executes' statements in sequence.
For example:
The role of ;; has nothing to so with top level sequencing:
the sequencing is already built in.
The purpose of ;; is much simpler -- it is nothing
more than a piece of punctuation marking the end
of a statement.
As you can see above it is not required if
(a) there is a next statement and
(b) that next statement starts with a keyword
You may need ;; in the interpreter to tell it
'there isn't another statement, start evaluating'.
You may also need it if you use a statement
not starting with a keyword, for example here:
where you can see that ;; is more or less the keyword
you use to start a statement when it doesn't start
with a keyword.. that isn't quite correct, since you
don't need one at the start (its really a separator
which is 'infered' when the parser hits an unexpected
keyword :)
This code is actually very ugly because you can't
lift it out of the top level.
is the way to do this properly -- and here the x := 1
is an expression contained in the let/in expression.
--
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850,
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net
The text was updated successfully, but these errors were encountered: