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

Re: Baffeld by manual (Was: [Caml-list] baffled by semicolon) #3124

Closed
vicuna opened this issue Aug 30, 2004 · 0 comments
Closed

Re: Baffeld by manual (Was: [Caml-list] baffled by semicolon) #3124

vicuna opened this issue Aug 30, 2004 · 0 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Aug 30, 2004

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:

briand@aracnet.com wrote:

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.

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

@vicuna vicuna closed this as completed Oct 6, 2004
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant