4

Which is the best way to handle the compatibility between two different Prolog interpreters? I've read this question and its answers but what I'm looking for is a methodology for coping with differently defined predicates (ie delete in SWI is not variable wise, while under YAP it is) and newly introduced predicates (ie remove_duplicates is not present in library(lists) in SWI).

At the moment I'm writing a file containing most of all predicates redefinitions but of course this gets one of the two (or more than two) compilers to yield a Warning for redefinition.

For the sake of semplicity you can assume that the Prolog implementation I'm interested in are SWI and Yap. Nevertheless a as general as it can be method would be highly appreciated.

Community
  • 1
  • 1
rano
  • 5,616
  • 4
  • 40
  • 66
  • Did you see this? http://www.swi-prolog.org/pldoc/doc_for?object=section(1,'C',swi('/doc/Manual/dialect.html')) –  Apr 05 '13 at 19:32
  • yep but it seems a compatibility layer for *others* towards SWI only. DO you know if it is portable itself? – rano Apr 05 '13 at 19:44
  • To me it looks like a minimal framework that supports conditional compilation for SWI and YAP (see also `dialect.pl` in the SWI documentation). At the end, to me it would seem that the only viable solution would be to code around the differences, when absolutely necessary, and stick to "vanilla" Prolog otherwise. –  Apr 05 '13 at 20:17

2 Answers2

2

I think that ISO Prolog should be the common subset reference.

But libraries are a massive problem. Indeed, I experienced an issue attempting to port a SWI-Prolog snippet to YAP.

...
:- use_module(library(assoc)).
:- use_module(library(aggregate)).
...

assoc library is implemented differently in these systems, and I was not able to make YAP version to work (If I remember well, gen_assoc((R, C), GridC, Char) had different semantic). Also, library(aggregate) had its problems under YAP.

To conditionally compile among these 2 systems, I attempted

/*  File:    prolog_impl.pl
    Author:  Carlo,,,
    Created: Jan 26 2013
    Purpose: handle SWI/YAP portability issue
*/

:- module(prolog_impl, [swi/0, yap/0, prolog_impl/1]).

swi :- prolog_impl(swi).
yap :- prolog_impl(yap).

prolog_impl(K) :-
    F =.. [K,_,_,_,_],
    current_prolog_flag(version_data, F).

but of course I'm not satisfied with this. I hope your question will bring some answer to the problem.

CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • Thanks for sharing. Is conditional compilation supported in other interpreters as well? Btw I too found many differences in library(assoc) under YAP and again the solution was to rewrite some predicate by myself. – rano Apr 05 '13 at 21:20
  • GnuProlog supports it. Any system having term_expansion could do as well, I think... – CapelliC Apr 05 '13 at 22:15
  • 1
    Conditional compilation is supported by an increasing number of Prolog compilers, including ECLiPSe, GNU Prolog, SICStus Prolog, SWI-Prolog, YAP, and XSB. Logtalk also supports the de facto standard conditional compilation directives. – Paulo Moura Apr 06 '13 at 08:32
2

Logtalk provides a compatibility layer with portable libraries supporting B-Prolog, CxProlog, ECLiPSe, GNU Prolog, Lean Prolog, Qu-Prolog, SICStus Prolog, SWI-Prolog, XSB, and YAP. Documentation on its libraries can be found at:

http://logtalk.org/library/index.html

http://logtalk.org/library/library_diagram.pdf

In the specific case of the "assoc" library mentioned in one of the replies to your question, Logtalk provides a protocol (aka interface) "dictionaryp" and two implementations of this protocol, "bintree" and "rbtree".

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
  • 1
    +1: I think Logtalk will be my next programming language, but I want first proceed/complete with my current SWI-Prolog involvement. – CapelliC Apr 06 '13 at 09:07
  • Note that there isn't an "either" here. You cannot (currently) run Logtalk without a backend Prolog compiler; Logtalk + SWI-Prolog makes a powerful combination. – Paulo Moura Apr 06 '13 at 13:48