Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-02-07 (14:13)
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:
> Archives:
> Beginner's list:
> Bug reports:

 	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(

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.