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=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 71166BC0C for ; Mon, 15 Jan 2007 21:24:25 +0100 (CET) Received: from out5.smtp.messagingengine.com (out5.smtp.messagingengine.com [66.111.4.29]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0FKOOTY010451 for ; Mon, 15 Jan 2007 21:24:25 +0100 Received: from out1.internal (unknown [10.202.2.149]) by out1.messagingengine.com (Postfix) with ESMTP id 5E4597BDA6; Mon, 15 Jan 2007 15:24:24 -0500 (EST) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by out1.internal (MEProxy); Mon, 15 Jan 2007 15:24:24 -0500 X-Sasl-enc: IR/Tjdym8ncmd/xhJAqY/3/q++an9IYiju3DPKFSqEtV 1168892663 Received: from [172.16.112.115] (burnham.ljcrf.edu [192.231.106.2]) by mail.messagingengine.com (Postfix) with ESMTP id 41D251F768; Mon, 15 Jan 2007 15:24:23 -0500 (EST) Date: Mon, 15 Jan 2007 12:23:32 -0800 (PST) From: Martin Jambon X-X-Sender: martin@localhost To: Vincent Hanquez Cc: Jon Harrop , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Ocaml compiler features In-Reply-To: <20070115000544.GA28731@snarc.org> Message-ID: References: <45A87011.8080203@gmail.com> <200701141823.32855.jon@ffconsultancy.com> <20070114184148.GA26213@snarc.org> <200701142049.57959.jon@ffconsultancy.com> <20070115000544.GA28731@snarc.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at concorde with ID 45ABE2F8.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ens-lyon:01 ocaml:01 compiler:01 camlp:01 camlp:01 ocaml:01 syntax:01 syntax:01 compilation:01 expansions:01 blabla:01 blabla:01 lexer:01 parser:01 lexer:01 On Mon, 15 Jan 2007, Vincent Hanquez wrote: > On Sun, Jan 14, 2007 at 08:49:57PM +0000, Jon Harrop wrote: > > Does it make code unsharable or can you apply multiple camlp4 macros to one > > piece of code? > > What I meant, is when you need to read code that used camlp4 you need to > learn almost a new language. It obviously depends of the changes, but > it's not pure OCaml. > > I can trivially find a lots of different incompatible syntax doing a 5s > search, that's the problem. > > The common syntax "extensions" should come with OCaml so that everyone > that use OCaml use the same language. I'm not saying camlp4 has no use, > but it should be limited to very specific use. OCaml is well-enough designed so that there is no "common" syntax extension. The problem is that people use it for a variety of things, and each domain may benefit from particular enhancements of the syntax. Either you incorporate all those extensions into the standard syntax, which is totally insane, or you consider them just as libraries. Loading a library is no big deal, whether it provides more functions or more syntax. IMHO the problem is more that writing camlp4 syntax extensions is very different from writing everyday OCaml code. In other words, it is inaccessible to beginners, and most other people think it's too complicated anyway. It requires too much expertise and only few people are able to maintain such code. Here is a list of things that I suggest if one ever wants to have a standard and widely use way of extending the syntax in OCaml: * implement a 2-stage (2, not n) compilation so that syntax extensions can be defined in standard OCaml modules. * each "macro" has a name and is provided as a module item. * there should a standard syntax for macro expansions, so that external readers know that a special syntax is being used. E.g. <:Mymodule.mymacro< blabla >> where blabla is parsed using the standard OCaml lexer, and the custom "mymacro" parser provided by module "Mymodule" (as opposed to current quotations where the content is parsed with any lexer). * defining a syntax extension should be done with some code which looks as much as possible like standard Ocaml. Here is an example. There are three new keywords "macro", "quote" and "pragma", plus some special syntax for writing the parser. "macro" is used to introduce the definition of a syntax extension. "quote" is used to represent the OCaml syntax tree and is available only in macro definitions. It would be a standard replacement for <:expr< ... >>, <:patt< ... >>, etc. Its type (expr, patt, str_item, ...) should be figured out automatically. "pragma" would introduce normal OCaml code which must be compiled during the first stage of the compilation (not shown in the example). macro cond stream = let subst e1 e2 e3 = (* could be defined externally using "pragma" *) match e1 with quote true -> e2 | quote false -> e3 | _ -> quote (if $e1 then $e2 else $e3) in parse stream with (* equivalent of an EXTEND statement with a single, new entry *) [ [ e1 = Ocaml.expr; e2 = Ocaml.expr; e3 = Ocaml.expr -> subst e1 e2 e3 | e1 = Ocaml.expr; e2 = Ocaml.expr -> subst e1 e2 (quote ()) ] ] (* same program, continuing *) let test_cond x y z = <:cond< (x + y = z) (z + 1) 0 >> (* is equivalent to: let test_cond x y z = if (x + y = z) then (z + 1) else 0 *) OK, there are many issues to solve, and it may not look as simple as advertised, but I am sure it can be done. Martin -- Martin Jambon http://martin.jambon.free.fr