Pengine Question: How to load multiple prolog files?

55 views
Skip to first unread message

dagobi

unread,
Sep 20, 2016, 4:31:54 AM9/20/16
to SWI-Prolog
Please refer to the Pengine example genealogist.pl as described in http://www.swi-prolog.org/pengines/Genealogist.html.

Suppose we split the file genealogist.pl into 2 files, exposing only ancestor_decendant/2 and siblings/2.

:- module(genealogist,
      [  ancestor_decendant/2,
         siblings/2
      ]).

ancestor_decendant(X, Y) :- parent_child(X, Y).
ancestor_decendant(X, Z) :- parent_child(X, Y), ancestor_decendant(Y, Z).

siblings(X, Y) :- parent_child(Z, X), parent_child(Z, Y), X @< Y.

parent_child(X, Y) :- mother_child(X, Y).
parent_child(X, Y) :- father_child(X, Y).

mother_child(trude, sally).

father_child(tom, sally).
father_child(tom, erica).
father_child(mike, tom).


How should I load parent_child.pl? Assume genealogist.pl is loaded via load.pl, as follows.

:- pengine_application(genealogist).
:- use_module(genealogist:'/apps/genealogist/genealogist.pl').

I will need to access ancestor_decendant/2 and siblings/2 through a Web GUI as described in http://www.swi-prolog.org/pengines/GenealogistGUI.txt.

Thanks much in advance!

Torbjörn Lager

unread,
Sep 20, 2016, 4:44:56 AM9/20/16
to dagobi, SWI-Prolog
Here is one way to do this:

In file genealogist.pl:

---

:- module(genealogist,
      [  ancestor_decendant/2,
         siblings/2
      ]).
     
:- use_module(parent_child).


ancestor_decendant(X, Y) :- parent_child(X, Y).
ancestor_decendant(X, Z) :- parent_child(X, Y), ancestor_decendant(Y, Z).

siblings(X, Y) :- parent_child(Z, X), parent_child(Z, Y), X @< Y.
---


In file parent_child.pl:

---
:- module(parent_child, [parent_child/2]).


parent_child(X, Y) :- mother_child(X, Y).
parent_child(X, Y) :- father_child(X, Y).

mother_child(trude, sally).

father_child(tom, sally).
father_child(tom, erica).
father_child(mike, tom).
---

Cheers,
Torbjörn


--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/swi-prolog.
For more options, visit https://groups.google.com/d/optout.



--
Torbjörn Lager
Professor of General and Computational Linguistics
Department of Philosophy, Linguistics and Theory of Science
University of Gothenburg
Box 200, SE-405 30 Gothenburg, Sweden
Phone: +46317864962

dagobi

unread,
Sep 20, 2016, 12:29:14 PM9/20/16
to SWI-Prolog, zack...@gmail.com
Thanks Torbjörn. 

Do I have to make parent_child into a module? Maybe I should have been more clear. What we need to do is to make an existing prolog app (with a main program and many supporting files) work with pengine, exposing only a couple of predicates of the main program. 

Without pengine we would just consult every file. Converting the main program into a module and consulting everything else does not seem to work.

Since there are many predicates like parent_child being used by the "main" program, it would be a lot of work if we have to convert every file into a module and "expose" every predicate that the main program is dependent upon. Predicates like parent_child is only used by the main program "internally", i.e., not to be used by the GUI.

Please let me know if I need to provide more info. 

Thanks again in advance!!
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.

Torbjörn Lager

unread,
Sep 20, 2016, 5:46:14 PM9/20/16
to dagobi, SWI-Prolog
Hi again,

I'm not completely clear on where your problem lies, but I can tell you as much as no, you don't have to make parent_child.pl into a module. There are other ways to load Prolog code. For maximum flexibility, have a look at load_files/2.

Hope this helps.
Best,
Torbjörn

To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+unsubscribe@googlegroups.com.

dagobi

unread,
Sep 21, 2016, 1:51:07 AM9/21/16
to SWI-Prolog, zack...@gmail.com
Thanks Torbjörn!
Reply all
Reply to author
Forward
0 new messages