From: skaller <skaller@users.sourceforge.net>
To: caml-list@pauillac.inria.fr
Cc: briand@aracnet.com, caml-bugs@inria.fr
Subject: Re: Baffeld by manual (Was: [Caml-list] baffled by semicolon)
Date: 30 Aug 2004 18:06:58 +1000 [thread overview]
Message-ID: <1093853217.9955.44.camel@pelican.wigram> (raw)
In-Reply-To: <4132D36D.4020104@bik-gmbh.de>
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
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2004-08-30 8:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-26 3:22 [Caml-list] baffled by semicolon briand
2004-08-26 3:30 ` David Brown
2004-08-26 4:18 ` Alex Valdez
2004-08-26 5:05 ` briand
2004-08-29 4:45 ` William Lovas
2004-08-30 7:12 ` Baffeld by manual (Was: [Caml-list] baffled by semicolon) Florian Hars
2004-08-30 8:06 ` skaller [this message]
2004-08-30 8:23 ` Radu Grigore
2004-08-30 8:25 ` Ville-Pertti Keinonen
2004-08-30 11:07 ` skaller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1093853217.9955.44.camel@pelican.wigram \
--to=skaller@users.sourceforge.net \
--cc=briand@aracnet.com \
--cc=caml-bugs@inria.fr \
--cc=caml-list@pauillac.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox