From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id F2901BC37 for ; Sun, 7 Feb 2010 15:13:07 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvgAAHhZbktCbwQakGdsb2JhbACPLIweAQEBAQkJDAcTBLkvBYRUgy8 X-IronPort-AV: E=Sophos;i="4.49,421,1262559600"; d="scan'208";a="43911139" Received: from out2.smtp.messagingengine.com ([66.111.4.26]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 07 Feb 2010 15:13:06 +0100 Received: from compute1.internal (compute1.internal [10.202.2.41]) by gateway1.messagingengine.com (Postfix) with ESMTP id D4544E0638; Sun, 7 Feb 2010 09:13:05 -0500 (EST) Received: from heartbeat2.messagingengine.com ([10.202.2.161]) by compute1.internal (MEProxy); Sun, 07 Feb 2010 09:13:05 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=messagingengine.com; h=date:from:to:cc:subject:in-reply-to:message-id:references:mime-version:content-type; s=smtpout; bh=5q1zWBkKSWdKTSbX6n3ZKvJPkj8=; b=K3VTMGLSJVls/70ZCzF9tZuEr+kpbZQtyUokJuTeZOgfRG/gb6O4tsjm4K+u14yFKQP0C43+Zcj6Rtp7TY0oCuQ6wS87EsSYAVgdwByzqpGCTIt4IS0x00VYuLjzvluBGRdkaElnv5B6aek+M9fO0qz4fghu7nDlGvgS2GfTNAU= X-Sasl-enc: HnbyAt0CL1fVZzXcGSSjUaPepW0PbqgqpP0Ls0FYh2U7 1265551984 Received: from [10.123.10.17] (softbank126112016066.biz.bbtec.net [126.112.16.66]) by mail.messagingengine.com (Postfix) with ESMTPSA id 43A4E200BC; Sun, 7 Feb 2010 09:13:04 -0500 (EST) Date: Sun, 7 Feb 2010 14:51:09 +0100 (CET) From: Joseph Young X-X-Sender: josyoun@myhome To: Andy Ray Cc: caml-list@inria.fr Subject: Re: [Caml-list] camlp4 In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Spam: no; 0.00; ocaml:01 camlp:01 camlp:01 syntax:01 ocaml:01 cheers:01 beginner's:01 bug:01 functor:01 functors:01 syntax:01 parser:01 nesting:01 beginners:01 wrote:01 On Sat, 6 Feb 2010, Andy Ray wrote: > Hi, > > My project would really benefit from some simple camlp4 syntax > extensions, however, I am put off by the lack of a reference manual > for it. > > At the moment I am tempted to go for camlp5 instead - not least > because I was able to work through it's manual and get some examples > working a while back. > > The reality is I would prefer to use camlp4 as it appears to the > official ocaml supported way, but can't see how to get into it as a > beginner due to the lack of documentation (and that appears to have > been the case for quite some time now). What should one do? > > Cheers, > Andy > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > Though slightly tangental, I use both camlp4 and camlp5 for the quotation system. As already mentioned, the lack of documentation is a problem, but it is not insurmountable. At this point, I prefer camlp4 to camlp5 for the following reasons. First, I like how locations are handled in camlp4 as opposed to camlp5. In camlp4, a function registered as a quotation accepts a string, a location, and optional location arguments. In camlp5, the function accepts only a string and the location information is passed in indirectly. I find this direct handling of locations easier to manipulate. Second, camlp4 allows me to register a quotation for a specific kind of ocaml ast (expression, pattern, whatever.) In camlp5, every time I register a quotation, I must supply code for both expressions and patterns. Third, although initially extremely confusing, I now prefer the functor organization that camlp4 uses. The functors make it clear as to how the syntax is extended. For example, the the original OCaml syntax is represented as an extension of the revised syntax. In order to create the appropriate original syntax module in camlp4, we use the code: module CamlSyntax=Camlp4OCamlParser.Make( Camlp4OCamlRevisedParser.Make( Camlp4.PreCast.Syntax));; Here, we can see that PreCast adds the necessary starting material, the revised parser adds the revised syntax, and the original syntax is an extension of the revised. Because of this organization, I find the relationship of syntax extensions more clear in camlp4. In order to make this organization more understandable, make sure you use ocamlbrowser and not the module M=Stuff trick on the top level. The nesting of modules in camlp4 is huge. In any case, both work extremely well and much of what you should use comes down to preference.