From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA15708; Mon, 30 Aug 2004 10:07:10 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA17573; Mon, 30 Aug 2004 10:07:09 +0200 (MET DST) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i7U876AK023980; Mon, 30 Aug 2004 10:07:08 +0200 Received: from [192.168.1.200] (ppp192-107.lns1.syd2.internode.on.net [203.122.192.107]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i7U86x4Y076145; Mon, 30 Aug 2004 17:37:00 +0930 (CST) Subject: Re: Baffeld by manual (Was: [Caml-list] baffled by semicolon) From: skaller Reply-To: skaller@users.sourceforge.net To: caml-list@pauillac.inria.fr Cc: briand@aracnet.com, caml-bugs@inria.fr In-Reply-To: <4132D36D.4020104@bik-gmbh.de> References: <16685.22393.76718.150882@soggy.deldotd.com> <4132D36D.4020104@bik-gmbh.de> Content-Type: text/plain Message-Id: <1093853217.9955.44.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 30 Aug 2004 18:06:58 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 4132E02A.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 baffled:01 semicolon:01 sourceforge:01 2004:99 florian:01 hars:01 sequencing:01 hackery:01 sequencing:01 unexpected:01 9660:01 glebe:01 evaluates:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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