From jan@swi.psy.uva.nl  Tue Jun 13 16:48:50 2000
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id QAA06082;
	Tue, 13 Jun 2000 16:48:49 +0200 (MET DST)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id QAA25497;
	Tue, 13 Jun 2000 16:49:31 +0200
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: Lalit Jain <lalit@savvion.com>,
        "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Subject: Re: Modules
Date: Tue, 13 Jun 2000 16:40:10 +0200
X-Mailer: KMail [version 1.0.28]
Content-Type: text/plain
Cc: jan@swi.psy.uva.nl, lalit@savvion.com, prolog@swi.psy.uva.nl
References: <Pine.GSO.4.21.0006121123150.4642-100000@neptune.tdiinc.com>
In-Reply-To: <Pine.GSO.4.21.0006121123150.4642-100000@neptune.tdiinc.com>
MIME-Version: 1.0
Message-Id: <00061316493108.24662@gollem>
Content-Transfer-Encoding: 8bit

On Mon, 12 Jun 2000, Lalit Jain wrote:

>Jan and Richard, Thanks a bunch for your help!
>
>My intention is to have the same set of predicates loaded into two or more
>different modules so that I can treat each module space as a session and
>assert different facts and execute different goals in each of them.
>
>For now, looks like the way I can do it is to create a module file for
>each one and include my original predicate file in it, such as:
>
>file: m1.pro
>:- module(m1, [])
>:- include('mypreds.pro').
>
>file m2.pro
>:- module(m2, [])
>:- include('mypreds.pro').
>
>Because I need to create these modules dynamically at runtime, I will need
>to create these files at runtime (I load the engine from C++).

Hmm.  Why don't you simply assert into the required module?  It seems a
bit odd to write out a file and load it just to create a module.  Just
do

	?- assert(m1:foobar).

and the system will create the module m1 and add a fact foobar.  Using
the predicates import and export you can also import and export to/from
dynamically created modules (not portable).

>Now when I load these files I have two distinct module spaces with the
>same predicates. Also, 'mypreds.pro' has some foreign predicates (loaded
>using load_foreign_library) and I realized that I'll need to call install
>functions seperately from each module with approprirate predicate names
>(such as PL_register_foreign(m1:foo, ..)  from module m1
>         PL_register_foreign(m2:foo, ..)  from module m2)
>
>Please let me know if you think there's a better way to do this.

This is possible, but you might consider to add them to the user module,
which makes them visible from all modules.  You can also add them to
some specific module and use export/import to relay them to the modules
where you need them.

>** I have one more question, which is, how can I destroy these modules at 
>runtime when I no longer need them ?? ** Is these some predicate to
>destroy a module space?

You cannot really destroy modules.  You can use predicate_property/2 to
enumerate all predicates and then abolish to get rid of them.  Note
that abolish on an imported predicates just removes the import, not
the predicate.  This way you can make the module empty.  The module
itself won't disappear.  If that is really needed (empty modules are
rather small), you need to add it to the base system.

	Regards --- Jan

