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: Loup Vaillant <loup.vaillant@g...>
Subject: Re: [Caml-list] C-like macros in OCaml
2007/6/27, Christopher L Conway <cconway@cs.nyu.edu>:
> 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 :
> > [...]
> > Will I get what I want?
>
> Probably not, but that depends on what you want. ;-) I believe that
> pa_macro DEFINEs have module scope.

Too bad. Actually, I want to implement a Lisp syntax for Ocaml, which
means I also want Lisp macros (regular and reader ones). Lisp macros
are often used extensively (Paul Graham talks about over 20% of the
code). That is why I want properly scoped macros : no global
namespace, and yet the possibility to use them between compilation
unit.

The only solution I came up with was producing at parsing type some
file for each .ml file containing a macro, so the preprocessor can
check these when parsing another file using this macro.

Hence my question : doesn't camlp4 provide a better solution to this
kind of problem? I know very little about the inner core of camlp4,
but I am sure I can reuse some ideas.


> 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

I will take a look, thanks for the pointer.

Loup