Conditional compilation
Author(s): Jose F. Morales.
This package defines a series of directives for conditional compilation that allow the inclusion or exclusion of code blocks (which may contain nested conditional directives) based on the truth value at compile time of special goals called conditions. The syntax for conditional directives is:
:- if(Cond1).
<<Block1>>
:- elif(Cond2).
<<Block2>>
:- else.
<<BlockN>>
:- endif.
where elif(_) can appear zero or more times and the else part is optional. The sentences in Block1 are included if the condition in Cond1 is satisfied, else Block2 is included if Cond2 is satisfied (and so on for each elif), and BlockN if no previous condition is satisfied.
Conditions
The valid conditions are restricted to a subset of goals that can be safely evaluated at compile time. At this moment, only the following ones are accepted:
- Compile-time values of prolog flags (current_prolog_flag/2).
- Conjunctions, disjunctions, or negations of conditions.
- Calls to facts previously defined with :- compilation_fact(Fact). This is an experimental feature that may change in the future. Calling a fact that is not declared is an error; :- compilation_fact((Head :- fail)) declares it with no clauses (a known false condition, e.g., the configuration of an absent optional part).
- defined(F/N) (or defined(F), equivalent to defined(F/0)), which succeeds only if there is a definition for the compilation fact F/N with some clause (so it fails for (F :- fail); unlike a call, it is not an error if F/N is not declared).
Usage and interface
- Library usage:
This module is imported by default (unless the noprelude or pure packages are used). - Implicit imports: