[1-14] How do you write portable programs in Prolog?

The de-facto standard syntax for Prolog is known as the Edinburgh
standard. It is based on the syntax of DEC-10 Prolog, an early Prolog
implementation developed at the University of Edinburgh.
See question [1-1] for information on the draft ISO standard for

Unfortunately, not every Prolog implementation is Edinburgh compatible.
There also isn't any notion of read-conditionalization, like #+ and #-
*features* in Common Lisp. 

One option is to use the C preprocessor on Prolog code before loading
it into Prolog.  Or you could use term-expansion to roll your own
conditional compilation system. Term expanding a clause to []
effectively discards it.

Another possibility is to conditionalize the execution instead of the
compilation. The user would have to uncomment a line like one of the
   % this_is(quintus).
   % this_is(sicstus).    
and the code would have to test for the proper literal
   a :- this_is(quintus), blah, blah, blah.
   a :- this_is(sicstus), blah, blah, blah.
at a slight cost in efficiency. (If you first feed the program through
a general partial evaluator, you'll get an equivalent program without
the inefficiency. Partial evaluation is in some sense a more powerful
and semantically cleaner form of source preprocessing. Given
        <head> :- <condition>, <rest of body>.
If <condition> is always false, we can safely drop the clause. If
<condition> is always true, we can drop it from any clauses that
include it.) 

Another possibility is Richard O'Keefe's environment package for
Prolog. It was posted to comp.lang.prolog on 1-SEP-94; a copy can be
found in
Go Back Up

Go To Previous

Go To Next