Message-Id: <v0151010caccff9db65eb@[204.5.215.14]>
Date: Wed, 15 Nov 1995 15:33:54 -0500
To: Christophe Raffalli <raffalli@cs.chalmers.se>, Michel.Mauny@inria.fr
From: e@flavors.com (Doug Currie, Flavors Technology, Inc.)
Subject: Re: Why no macros in CAML Light ?
At 6:43 PM 11/15/95, Christophe Raffalli wrote:
>> Even simpler: use the C preprocessor itself! (with the -P option)
>> I know, it is tractable only under Unix, and using Makefiles...
>
>I do it on my mac ....
Not with CodeWarrior :-( which seems to require C syntax in the
preprocessor. Do you use MPW?
I would like to see a simple macro mechanism in Caml Light (and other ML
languages) to avoid the use of cpp and make.
One possibility... LISP has an intermediate mechanism between preprocessor
and full compiler macros, reader macros. A particular set of reader macros
"#+" and "#-" are useful for the types of things the C preprocessor does. A
simplified description of how they work could work in ML is as follows:
The compiler maintains a list of "features." Interactive user code, or
makefiles, or other mechanisms, may add to the features list -- it is just
an ML list of strings. The reader (lexer) treats the #+ and #- tokens
specially. If the token following the #+ is a string on the features list,
then the next token [expression] is processed, otherwise it is discarded.
If the token following the #- is a string not on the features list, then
the next token [expression] is processed, otherwise it is discarded.
This doesn't require any change to the compiler per se (just the lexer) and
does not require an "eval" mechanism.
For example, to distinguish constants for 32 bit versus 64 bit
implementations, you could use:
let size = #+"32bit" 0x40000000 #+"64bit" 0x4000000000000000
For a function only available in UNIX implementations:
#+"UNIX"
(
let chmod file xxx = ... ;;
)
Or for a function not available on the Mac:
#-"Macintosh"
(
let system str = ... ;;
)
e