From fisch@email.arc.nasa.gov Fri Nov  9 20:52:30 2001
Received: from email.arc.nasa.gov (email.arc.nasa.gov [143.232.64.51])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id fA9JqTt27960
	for <prolog@swi.psy.uva.nl>; Fri, 9 Nov 2001 20:52:30 +0100 (MET)
Received: from bowl (bowl.arc.nasa.gov [143.232.66.79])
	by email.arc.nasa.gov ( -- Info omitted by ASANI Solutions, LLC.) with SMTP id LAA07205
	for <prolog@swi.psy.uva.nl>; Fri, 9 Nov 2001 11:52:29 -0800 (PST)
From: "Bernd Fischer" <fisch@email.arc.nasa.gov>
To: "SWI Prolog (list)" <prolog@swi.psy.uva.nl>
Date: Fri, 9 Nov 2001 11:56:11 -0800
Message-ID: <NDBBLGANCLGPPKPLENDJKEKICPAA.fisch@email.arc.nasa.gov>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
Subject: [SWIPL] Cloning and updating a module

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                 fisch@email.arc.nasa.gov
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

