Version française
Home     About     Download     Resources     Contact us    
Browse thread
C-like macros in OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christopher L Conway <cconway@c...>
Subject: Re: [Caml-list] C-like macros in OCaml
On 6/27/07, Loup Vaillant <loup.vaillant@gmail.com> wrote:
> By the way, does camlp4 handle cross modules C-like macros? If it does, how?
> For instance, what if I write, in foo.ml :
> DEFINE FOO = 1
>
> and then, in bar.ml :
> let bar = FOO;;
>
> or else:
> open foo;;
> let bar = FOO;;
>
> or even :
> let bar = Foo.FOO;;
>
> Will I get what I want?

Probably not, but that depends on what you want. ;-) I believe that
pa_macro DEFINEs have module scope. To get the same DEFINE in multiple
files, you can use -D arguments on the command line, but pa_macro
doesn't allow these arguments to have values (i.e., you can only test
IFDEF/IFNDEF).* If you want arguments, see pa_macro_arg:
http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=569

Chris

* I submitted a patch for this, but I don't think it's made its way
into a release. I didn't realize the 3.10/new camlp4 push was on when
I made it.

> Now, what about regular quotations? And grammar rules? How can I
> specify the scope of particular grammar rule (or quotation)? For the
> little I know about camlp4, once defined, the scope of a new grammar
> rule is global. (Idem for quotations).
>
> Am I right?
> Any clue about the way camlp4 keep track of new grammar rules an
> quotations? (Or some pointer to the documentation involved)
>
> Thanks
> Loup Vaillant
>
> _______________________________________________
> 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
>
>