C Compatibility with other Prolog dialects

This chapter explains issues for writing portable Prolog programs. It was started after discussion with Vitor Santos Costa, the leading developer of YAP Prolog90http://yap.sourceforge.net/ YAP and SWI-Prolog have expressed the ambition to enhance the portability beyond the trivial Prolog examples, including complex libraries involving foreign code.

Although it is our aim to enhance compatibility, we are still faced with many incompatibilities between the dialects. As a first step both YAP and SWI will provide some instruments that help developing portable code. A first release of these tools appeared in SWI-Prolog 5.6.43. Some of the facilities are implemented in the base system. Others in the library library(dialect.pl).

:- expects_dialect(+Dialect)
This directive states that the code following the directive is written for the given Prolog Dialect. See also dialect. The declaration holds until the end of the file in which it appears. The current dialect is available using prolog_load_context/2.

The exact behaviour of this predicate is still subject to discussion. Of course, if Dialect matches the running dialect the directive has no effect. Otherwise we check for the existence of library(dialect/Dialect) and load it if the file is found. Currently, this file has this functionality:

exists_source(+Spec)
Is true if Spec exists as a Prolog source. Spec uses the same conventions as load_files/2. Fails without error if Spec cannot be found.
source_exports(+Spec, +Export)
Is true if source Spec exports Export, a predicate indicator. Fails without error otherwise.


Section Index


C.1 Some considerations for writing portable code