Global predicates in SWI and Sicstus Prolog
From: Christoph Quix (cqx_at_gmx.de)
Date: 08/23/04
- Next message: Bart Demoen: "Re: Global predicates in SWI and Sicstus Prolog"
- Previous message: Henry Polley: "Gprolog and QT"
- Next in thread: Bart Demoen: "Re: Global predicates in SWI and Sicstus Prolog"
- Reply: Bart Demoen: "Re: Global predicates in SWI and Sicstus Prolog"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 23 Aug 2004 10:59:53 +0200
Hi all!
I am still working on porting an application from MasterProlog
to SWI and/or Sicstus Prolog. As you might know, MasterProlog does
have a "global" directive, e.g.
:- global bar/1 .
means that the predicate is visible within all modules, without being
imported explicitly.
I want to achieve the same effect with SWI and Sicstus Prolog.
Here are my observations/problems.
1. SWI-Prolog (5.2.13)
I can achieve about the same effect by using a source file
without a module directive, i.e. global predicates will be
defined in the "user" module, and therefore they will be visible
in all modules.
I have made two source files with the following contents:
------ file1 --------
:- module(test,[foo/1]).
foo(X) :- bar(X).
------ file2 --------
:- dynamic bar/1 .
bar(z).
---------------------
The question
?- foo(X).
leads to the expected result X=z.
If I do assert(test:bar(x)), I get as additional
result X=x, so there is obviously no difference between
the predicates user:bar/1 and test:bar/1 , but I think
that will be no problem for me.
So, I am more or less satisfied with this solution for
SWI Prolog, unless someone knows a better way.
2. Sicstus Prolog
Assuming that the module systems of SWI and Sicstus are
quite similar, I tried the same solution for Sicstus. Using
the same source files, I get an error message on the question:
?- foo(X).
Existence error in test:bar/1
procedure test:bar/1 does not exist
goal: test:bar(_82)
So, how can I make bar/1 visible within the "test" module?
use_module(user) can't be the solution (it prompts for user input).
The order in which I consult the files does not make a difference.
Any help appreciated,
Christoph
- Next message: Bart Demoen: "Re: Global predicates in SWI and Sicstus Prolog"
- Previous message: Henry Polley: "Gprolog and QT"
- Next in thread: Bart Demoen: "Re: Global predicates in SWI and Sicstus Prolog"
- Reply: Bart Demoen: "Re: Global predicates in SWI and Sicstus Prolog"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]