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 TAA00927; Thu, 5 Apr 2001 19:43:56 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA00902 for caml-list@pauillac.inria.fr; Thu, 5 Apr 2001 19:43:56 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA20637 for ; Thu, 5 Apr 2001 00:59:03 +0200 (MET DST) Received: from moutvdom00.kundenserver.de (moutvdom00.kundenserver.de [195.20.224.149]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f34Mx3H11284 for ; Thu, 5 Apr 2001 00:59:03 +0200 (MET DST) Received: from [195.20.224.209] (helo=mrvdom02.schlund.de) by moutvdom00.kundenserver.de with esmtp (Exim 2.12 #2) id 14kwEw-00015Z-00; Thu, 5 Apr 2001 00:59:02 +0200 Received: from drms-3e364bb6.pool.mediaways.net ([62.54.75.182] helo=ice.gerd-stolpmann.de) by mrvdom02.schlund.de with esmtp (Exim 2.12 #2) id 14kwFk-0006gm-00; Thu, 5 Apr 2001 00:59:53 +0200 Received: from localhost (localhost [[UNIX: localhost]]) by ice.gerd-stolpmann.de (8.9.3/8.9.3) id AAA31649; Thu, 5 Apr 2001 00:58:48 +0200 From: Gerd Stolpmann Reply-To: gerd@gerd-stolpmann.de Organization: privat To: Chris Hecker , caml-list@inria.fr Subject: Re: [Caml-list] semi-colons and begin Date: Thu, 5 Apr 2001 00:40:30 +0200 X-Mailer: KMail [version 1.0.28] Content-Type: text/plain References: <4.3.2.7.2.20010404142255.0338a1c0@shell16.ba.best.com> In-Reply-To: <4.3.2.7.2.20010404142255.0338a1c0@shell16.ba.best.com> MIME-Version: 1.0 Message-Id: <01040500584807.00489@ice> Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, 04 Apr 2001, Chris Hecker wrote: >I must admit I'm still slightly confused about the semicolon thing, even after writing a fair amount of caml code. The current sticking point is that > ># if false then print_int 2; print_int 3;; >3- : unit = () > ># if false then print_int 2; print_int 3 else ();; >Characters 39-43: >Syntax error ># > ># if false then begin print_int 2; print_int 3 end;; >- : unit = () ># if false then begin print_int 2; print_int 3 end else ();; >- : unit = () > >The "BNF" grammar implies the first and second tests should compile and print nothing, >since expr = expr ; expr, although Xavier et al. have said the BNF in the docs >isn't really accurate. The BNF is ambigous (as most grammars). So you can't say which is the right way to set the parentheses: (if false then print_int 2); print_int 3 -- OR if false then (print_int 2; print_int 3) Both ways are correct if you only look at the grammar. However, in the O'Caml manual there is a precedence table (section 6.7) determining that "if" has higher precedence than ";". So the first way is what the compiler interprets. > >also thought begin...end was needed in a >pattern-match, but apparently expr ; expr works there? In the precedence table "match" has lower precedence than ";". >Is there a chart or something that says exactly where they're allowed? I'm >afraid of introducing a subtle bug in my program. In C I always use brackets >with my if statements to avoid the similar problem, so I suppose I could use >begin..end everywhere, but yuck! You can use begin ... end (or (...) which is the same) everywhere in expressions. But I don't recommend it because it makes code unreadable which is another cause for errors. I personally have no problems with "if" because it is in the same style as in the first structured programming language I've learned (Pascal). If you have problems I would recommend to use Emacs as editor with one of the two O'Caml modes. It automatically indents the code, so you see: if false then print_int 2; print_int 3 and _not_ if false then print_int 2; print_int 3 which would mean that you did it wrong. Gerd -- ---------------------------------------------------------------------------- Gerd Stolpmann Telefon: +49 6151 997705 (privat) Viktoriastr. 100 64293 Darmstadt EMail: gerd@gerd-stolpmann.de Germany ---------------------------------------------------------------------------- ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr