From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 2A9ADBC69 for ; Mon, 20 Aug 2007 08:26:57 +0200 (CEST) Received: from ipmail01.adl2.internode.on.net (ipmail01.adl2.internode.on.net [203.16.214.140]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7K6QsLH014063 for ; Mon, 20 Aug 2007 08:26:56 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAKvPyEZ5LGJp/2dsb2JhbAAM X-IronPort-AV: E=Sophos;i="4.19,283,1183300200"; d="scan'208";a="175942598" Received: from ppp121-44-98-105.lns10.syd6.internode.on.net (HELO [192.168.1.201]) ([121.44.98.105]) by ipmail01.adl2.internode.on.net with ESMTP; 20 Aug 2007 15:56:26 +0930 Subject: Re: [Caml-list] If OCaml were a car From: skaller To: Jon Harrop Cc: caml-list@yquem.inria.fr In-Reply-To: <200708200437.59877.jon@ffconsultancy.com> References: <56864F61-40F3-4F03-9823-6D510AD5320B@epfl.ch> <1187559941.6987.40.camel@rosella.wigram> <200708200437.59877.jon@ffconsultancy.com> Content-Type: text/plain Date: Mon, 20 Aug 2007 16:26:24 +1000 Message-Id: <1187591184.6295.36.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 46C9342E.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 0100,:01 expr:01 expr:01 bool:01 ocaml:01 btyp:01 elided:01 dfns:01 btyp:01 non-terminal:01 syntax:01 'let:01 semantics:01 semantics:01 On Mon, 2007-08-20 at 04:37 +0100, Jon Harrop wrote: > > > > The thing is that 'else' has a different 'precedence' than 'then'. > > So you can write: > > > > if e then e1 else a; b; c > > > > and a,b,c are all executed if the condition is false, > > I do not believe this is true. The "b" and "c" are executed in both cases > because the above is parsed as: > > (if e then e1 else a); b; c > > which is syntactically uniform: > > # (<:expr< (if true then a else a);b;c >>) = > (<:expr< if true then a else a;b;c >>);; > - : bool = true > > Perhaps you were thinking of this: > > if p then t else > let () = () in > f1; > f2; > f3 > > because "let" binds more tightly. Well there you go! I've been writing Ocaml almost 10 years and didn't know that. Here's my real code: if ret = `BTYP_tuple [] then "// elided (returns unit)\n","" else let funtype = fold syms.dfns (`BTYP_function (argtype, ret)) in I guess I'm just lucky. From what you say, the grammar is exceptionally bad: the scope of the 'else' is *extended* by the let/in non-terminal so it goes past ';' -- that should be a syntax error. Roughly a 'loosely' binding operator is extending the scope of a 'tightly' binding operator: doing that is fragile. For example if I drop the 'let .. in' part the semantics may** change silently. The 'right' way to extend a scope is to use an scope extension operator with no semantics, such as ( .. ) or begin .. end, or $ in Felix in Haskell. But please note: just because I present this analysis doesn't mean I believe it 100%. Contrarily .. it is just a data point. It has to be weighted against other factors: every syntactic form has both advantages and disadvantages, and it is very dependent on the client's prior experience. *** German, for example, has the ridiculously clumsy grammar of putting the verb at the end and concatenating adjectives onto nouns: "Ein Schwartz-Wald-Spatzieren-Gehen" = "A Walk in the Black Forest" .. literally "A Black Forest Walk Going" (FYI: a famous jazz number from the '60s). I'd probably fall over laughing at how stupid French is :) Except .. I happen to know English is the most absurd language around. It just happens to be my native language so I'm used to it. ** it's likely I'll get a type error and become very confused, but that is much better than not getting a type error, which is quite possible if everything is returning unit. *** when I designed Felix I made a decision that the grammar had to be LALR1 and entirely unambiguous, a choice easily enforced by using Ocamlyacc (without any %prec rubbish, and by grepping the .output to make sure there were no shift/reduce conflicts). -- John Skaller Felix, successor to C++: http://felix.sf.net