Subject: [SWIPL] Cloning and updating a module

From: "Bernd Fischer" <[email-masked]>
Date: Fri, 9 Nov 2001 11:56:11 -0800

Hi,

I want to use modules to represent multiple dynamic worlds.
However, I haven't figured out how to create a ''clone'' of
a world which can then be updated without affecting the world
it orginated from. Here's what I do:

Define m1.pl:

> :- module(m1, [q/1]).
> :- dynamic q/1.
> q(a).

Compile it:

> 1 ?- [m1].
> % m1 compiled into m1 0.00 sec, 896 bytes
>
> Yes
> 2 ?- listing(m1:q).
>
> :- dynamic q/1.
>
> q(a).
>
> Yes

Try to clone m1 into m2:

> 3 ?- export_list(m1, L), checklist(m2:export, L).
>
> L = [q(_G498)]
>
> Yes

Everything looks ok:

> 4 ?- listing(m2:q).
> :- dynamic q/1.
> q(a).
> Yes

But it isn't - the update / extension destroys the state copied from
the old world:

> 5 ?- m2:assert(q(b)).
> Yes
> 6 ?- listing(m2:q).
> :- dynamic q/1.
> m2:q(b).
> Yes

In the old world, this works as expected:

> 9 ?- m1:assert(q(b)).
> Yes
> 10 ?- listing(m1:q).
> :- dynamic q/1.
> q(a).
> q(b).
> Yes

Where's my mistake? What is the best way to clone a module? Does
anybody have some example code using modules they could share?
Also, how efficient is this mechanism? What runtime costs do I
incur if I want to clone larger modules which contain, say, a few
hundred facts and rules? Is there a structuring / sharing mechanism?

Thanks in advance,

-- fisch

--
------------------------------------------------------------------------------
Bernd Fischer                             Automated Software Engineering Group
USRA/RIACS, NASA Ames Research Center                 [email-masked]
M/S 269-2                               http://ase.arc.nasa.gov/people/fischer
Moffett Field, CA 94035, USA             +1(650)604-2977  fax 4036  rm 269-239