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: Jeremy Yallop <jeremy.yallop@e...>
Subject: Re: [Caml-list] C-like macros in OCaml
Richard Jones wrote:
> On Tue, Jun 26, 2007 at 05:00:40PM -0500, Raj B wrote:
>> Hi there
>>
>> Is there any way I can achieve the use of C-like preprocessor macros  
>> in OCaml?
>> i.e.
>>
>> #define FOO 1
>>
>> etc.
> 
> What about ocamlc -pp /lib/cpp ? :-)
> 
> There's also a camlp4 macro preprocessor, but I can't remember now
> whether it can do constant defines like that (IIRC it used not, but
> now it can, or something like that).

It appears to support them.  If you have a file `foo.ml' containing the 
following:

     DEFINE FOO = 1

     let x = FOO

then compiling it with pa_macro under 3.09 gives:

     $ camlp4 pa_o.cmo pa_macro.cmo pr_o.cmo foo.ml
     (* *)

     let x = 1

or with the built-in Camlp4MacroParser under 3.10:

     $ camlp4of foo.ml
     let x = 1

Jeremy.