From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id D2B5EBC6C for ; Wed, 27 Jun 2007 09:40:31 +0200 (CEST) Received: from bdmail1.accesst.com (pop.bulldoghome.com [83.245.1.230]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5R7eVTx017341 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 27 Jun 2007 09:40:31 +0200 Received: from host-84-9-232-87.bulldogdsl.com ([84.9.232.87] helo=[192.168.123.191]) by bdmail1.accesst.com with esmtpa (Exim 4.50) id 1I3S0N-0006uN-TY; Wed, 27 Jun 2007 08:32:00 +0100 Message-ID: <46821522.80602@ed.ac.uk> Date: Wed, 27 Jun 2007 08:43:30 +0100 From: Jeremy Yallop User-Agent: Mozilla-Thunderbird 2.0.0.4 (X11/20070618) MIME-Version: 1.0 To: Richard Jones Cc: Raj B , caml-list@yquem.inria.fr Subject: Re: [Caml-list] C-like macros in OCaml References: <1B4EC64C-435D-42C5-95F3-C01869DD41FB@rice.edu> <20070627041034.GA7232@furbychan.cocan.org> In-Reply-To: <20070627041034.GA7232@furbychan.cocan.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 4682146F.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; c-like:01 ocaml:01 c-like:01 ocaml:01 foo:01 ocamlc:01 -pp:01 lib:01 cpp:01 camlp:01 defines:01 iirc:01 foo:01 ml':01 camlp:01 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.