Version française
Home     About     Download     Resources     Contact us    
Browse thread
camlp4
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Joseph Young <ocaml@o...>
Subject: Re: [Caml-list] camlp4
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.