caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jeremy Yallop <jeremy.yallop@ed.ac.uk>
To: Richard Jones <rich@annexia.org>
Cc: Raj B <rajb@rice.edu>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] C-like macros in OCaml
Date: Wed, 27 Jun 2007 08:43:30 +0100	[thread overview]
Message-ID: <46821522.80602@ed.ac.uk> (raw)
In-Reply-To: <20070627041034.GA7232@furbychan.cocan.org>

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.


  reply	other threads:[~2007-06-27  7:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-26 22:00 Raj B
2007-06-26 22:06 ` [Caml-list] " Jonathan Bryant
2007-06-27  4:10 ` Richard Jones
2007-06-27  7:43   ` Jeremy Yallop [this message]
2007-06-27  8:08     ` Loup Vaillant
2007-06-27 12:53       ` Christopher L Conway
     [not found]         ` <6f9f8f4a0706280037h5f19af5flb764e1c2999b0337@mail.gmail.com>
2007-06-28  7:38           ` Loup Vaillant
2007-06-28  7:44         ` Nicolas Pouillard
     [not found] <20070627044609.6B456BC77@yquem.inria.fr>
2007-06-27  7:21 ` David Allsopp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46821522.80602@ed.ac.uk \
    --to=jeremy.yallop@ed.ac.uk \
    --cc=caml-list@yquem.inria.fr \
    --cc=rajb@rice.edu \
    --cc=rich@annexia.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).