1

In SWI-Prolog, I am using code such as at the beginning of a module text file:

:- module(foo, [bar/2]).
:- use_module(library(jack)).

I don't want to change my code. How can I neverthelss use ECLiPSe Prolog (*). Is there some library that defines a module/2 directive in ECLiPSe Prolog?

Best Regards

(*) http://eclipseclp.org/

4 Answers4

2

You can compile Prolog module that uses SWI-Prolog module system using Logtalk for use with ECLiPSe (or any other of the supported Prolog compilers, including those that don't provide a module system).

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
  • Prolog modules that start with a `module/2` directive are compiled by Logtalk as objects with the export list being interpreted as public resources. I.e. the `module/2` directive it's already supported. No need to define it. See http://logtalk.org/manuals/userman/migration.html#migration_compiling – Paulo Moura Mar 23 '14 at 20:15
1

The following code defines a macro that maps module/2 into module/3 directives:

:- export macro((:-)/1, translate_directive/2, [top_only]).
translate_directive(
    (:- module(Module, Exports)),
    (:- module(Module, Exports, [swi]))
).

Compile (or import) this before compiling the module written for SWI. Note that the 3rd argument of module/3 must contain a language module, corresponding to the dialect your module is written in. I have used swi here, other choices would be quintus, iso or ECLiPSe's native eclipse_language.

jschimpf
  • 4,904
  • 11
  • 24
0

No, there are only module/1 and module/3.

You an see the list of all what available here: http://eclipseclp.org/doc/bips/fullindex.html

Sergii Dymchenko
  • 6,890
  • 1
  • 21
  • 46
0

SWI-Prolog (an others) module/2 directives can be replaced on ECLiPSe by module/1 + export/1 directives as you likely already found out. Also both SWI-Prolog and ECLiPSe support conditional compilation directives and the dialect flag. This should provide you with another alternative (not tested) for using the same Prolog files with both systems:

:- if(current_prolog_flag(dialect, swi)).

    :- module(foo, [p/1]).

:- elif(current_prolog_flag(dialect, eclipse)).

    :- module(foo).
    :- export(p/1).

:- else.

    ...

:- endif.
Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
  • Would a call to prolog_load_context(dialect, ...) be more correct? In case the above is part of a client code, that can change the dialect? Probably not needed since module/[1,2] are supposed to be some of the earlier steps in loading a Prolog text. –  Sep 26 '14 at 15:21
  • The `prolog_load_context/2` predicate is usually called from the term-expansion predicates. So, yes, it could be used for a solution similar to the one posted by Joachim. But this is far from an universal predicate. It would be preferable to check the value of the `dialect` de facto standard Prolog flag using the standard `current_prolog_flag/2` predicate. – Paulo Moura Sep 26 '14 at 18:24