mercury

How do I specify compile time defines in Mercury?


How do I specify compile time defines in Mercury?

I would like to have the build system read the version number out of a configuration file and pass it into the module for access by predicates and functions.

For example, in C I'd do something like: gcc -DVERSION="1.2.0", and then use the newly defined macro VERSION in the source.


Solution

  • Zoltan Somogyi on the Mercury Users Mailing List Responded with:

    [Compile time defines, like in C, aren't possible in Mercury], because it is that is a piece of functionality that is rarely needed, which is easy to achieve without special support within Mercury itself.

    ....

    [For your specific need, pushing in the version number from the build system] Have something like a file named version.m.in containing

    :- module version.

    :- interface. :- func version = string.

    :- implementation. version = "@VERSION@".

    and then have a shell or sed script that constructs version.m from version.m.in by replacing @VERSION@ with the actual version string. If you want the version string to change without human intervention (e.g. to reflect the current date), you would then add an mmake rule to construct version.m from version.m.in automatically at appropriate points in time.