[mercury-users] Conditional compilation
Ralph Becket
rafe at cs.mu.OZ.AU
Tue Feb 5 17:25:47 AEDT 2002
Michael Day, Tuesday, 5 February 2002:
>
> Is there any way to achieve conditional compilation in Mercury without
> resorting to foreign_code #ifdef hackery?
>
> More precisely, say you have a program that can do several different
> things and you wish to specify which of those things should be compiled in
> without having to edit the code manually each time. Presumably Mercury
> itself has something along these lines for supporting a particular set of
> grades, specified by the configure script?
You could have a module with various compilation flags set as simple
predicates:
:- module compilation_options.
:- interface.
:- import_module bool.
:- pred option1 is det.
:- pred option2 is det.
:- pred option3 is failure.
:- pred option4 is det.
...
:- implementation.
:- pragma inline(option1/0).
option1.
:- pragma inline(option2/0).
option2.
:- pragma inline(option3/0).
option3 :- fail.
:- pragma inline(option4/0).
option4.
...
Then you just write code like this:
...
( if option1 then <option1 specific code> ),
( if option2 then <option2 specific code> ),
( if option3 then <option3 specific code> ),
( if option4 then <option4 specific code> ),
...
The optionX predicates should be inlined and the if-thens optimized
away.
It's not hugely pretty, but it is doable.
- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list