Subject: Re: Modules

From: Jan Wielemaker <[email-masked]>
Date: Fri, 9 Jun 2000 13:46:54 +0200

On Fri, 09 Jun 2000, Lalit Jain wrote:
>Hi All:
>My question is regarding modules. I have a file containing some
>predicates
>(not belonging to any module).
>Now I load the file under the context of a module, say m1; and i can see
>all the predicates when i do listing.
>Then, I load the same file under the context of another module, say
>m2; again I see all the predicates.
>Now, I switch to module m1, and I don't see any predicates there. Why is
>that so?

Because the system remembers which clauses come from which file.  If a
file is reloaded, all clauses resulting from the previous load will be
removed.

To get the same clauses into multiple modules, write a file defining
a module and use use_module/1 to load and import the clauses.

You can also have a look at the ISO include(File), which can appear
as a directive in a file and expands to the terms read from File.

	Regards --- Jan

>I have a file foo as:
>
>foo(1).
>
>Now at the prolog interpreter, i say,
>
>1 ?- module(m1).
>Warning: m1 is not a current module (created)
>
>Yes
>m1: 2 ?- [foo].
>% foo compiled into m1 0.01 sec, 520 bytes
>
>Yes
>m1: 3 ?- listing.
>
>foo(1).
>
>Yes
>m1: 4 ?- module(m2).
>Warning: m2 is not a current module (created)
>
>Yes
>m2: 5 ?- [foo].
>% foo compiled into m2 0.00 sec, 128 bytes
>
>Yes
>m2: 6 ?- listing.
>
>foo(1).
>
>Yes
>m2: 7 ?- module(m1).
>
>Yes
>m1: 8 ?- listing.
>
>Yes
>m1: 9 ?- 
>
>
>Thanks,
>Lalit
>
>
>
>
>
>----------------
>* To UNSUBSCRIBE, please use the HTML form at
>
>    http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist
>
>or send mail to [email-masked] using the Subject: "unsubscribe"
>(without the quotes) and *no* message body.
>
>** An ARCHIVE of this list is maintained at
>
>    http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/