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
camlp4 -I and shared libs
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-06-29 (14:06)
From: Nicolas Pouillard <nicolas.pouillard@g...>
Subject: Re: [Caml-list] camlp4 -I and shared libs
On 6/29/07, Benedikt Grundmann <> wrote:
> Hi everybody,
> At the risk of sounding harsh, I do not like this wiki at all, due to
> several reasons:
> 1) Default style sheet is a partial user interface nightmare, a lot of
> the links are embedded in  titles, which happen to have nearly the
> same styling... So you actually have to hover above each title to find
> the links.

You're right.

> 2) Structure is a mess...  Camlp4 can do a lot and that is great.  But
> I do believe that the primary motivation is the extension of OCaml and
> some simple examples, or even better yet some kind of tutorial is
> needed. It definitely should start simple maybe even over simplifying
> things and very very gradually introduce the true power...

Yes but, for now I was more concentrated on explaining differences and
improvements, and that's about advanced features.


> PS: I do not want to start a flame war, or offend the creators of the
> Wiki.  I just wanted to point out that right now the wiki is not
> helpful, unless you already now a lot about camlp4...

That's a good point, that I am aware of.

> PPS: My syntax extension captures the identifier msg.  How is one
> supposed to write hygienic macros?  Should I just store a counter
> somewhere and generate identifiers like "msg__32432" and hope that
> nobody else uses the same prefix, or is there some support for things
> like that in camlp4?

You can start by checking that the user don't use that variable.

Using the generated fold it's easy.

$ cat
open Camlp4.PreCast;;
let filter = object (o) inherit Ast.fold as super

  (* capture most of cases *)
  method ident i =
     let o = super#ident i in
     match i with
     | <:ident< msg >> -> failwith "msg forbidden"
     | _ -> o

  (* there is perhaps some more... *)
  method expr e =
     let o = super#expr e in
     match e with
     | <:expr< for msg = $_$ $to:_$ $_$ do $_$ done >> -> failwith
"msg forbidden"
     | _ -> o
AstFilters.register_str_item_filter (fun st -> let _ = filter#str_item st in st)

$ ocamlc -c -I +camlp4 -pp camlp4of

$ cat
let msg = 42

$ camlp4o ./foo.cmo

Nicolas Pouillard