deep copies

1 view
Skip to first unread message

Nate Blaylock

unread,
May 1, 2007, 2:46:32 PM5/1/07
to km-qa
Hi all,

is this list still active?

Does anyone know if there are any functions in KM for making deep
copies of an instance (i.e., copying it as well as (recursively) the
instances in its slots such that any changes to the copy will not
change the original)?

If not, any hints at what to beware of if one were to try to write
such a function?

thanks,

nate

Pete

unread,
May 1, 2007, 4:11:47 PM5/1/07
to km-qa
Nate -

The nearest thing is KM's prototype mechanism, which allows you
to create a network of instances (what you're calling a "deep
instance"0 which can then be cloned using the (clone <prototype-
instance>)
command, see Section 22 in the User Manual. However, this only works
with special prototype instances, not normal instances.

You can trick KM into thinking a normal instance is a prototype
by (i) asserting it's a prototype-of something and (ii) adding
a prototype-participants slot, listing all the instances in this
graph (or "deep instance" as you call it). Then a (clone <instance>)
operation will do what you want.

Note that named instances (i.e., not starting with a "_") are NOT
cloned, simply copied direct (see *black below).

Best wishes!

Pete

--------------------------------------------------

KM> (_Car1 has (instance-of (Car)) (has-part (_Engine1)))
KM> (_Engine1 has (instance-of (Engine)) (has-part (_Cylinder1)))
KM> (_Cylinder1 has (instance-of (Cylinder)) (color (*black)))

;;; Now trick KM into thinking KM's a prototype
KM> (_Car1 has (prototype-of (Car))
(prototype-participants (_Car1 _Engine1 _Cylinder1)))

;;; Now clone it
KM> (clone _Car1)
(_Car7)

;;; Inspect the clone to see all the bits are there
KM> (showme _Car7)
(_Car7 has
(instance-of (Car))
(parts (_Engine8))
(has-part (_Engine8))
(cloned-from (_Car1))
(clone-built-from (_Car1)))

KM> (showme _Engine8)
(_Engine8 has
(parts-of (_Car7))
(has-part-of (_Car7))
(instance-of (Engine))
(parts (_Cylinder9))
(has-part (_Cylinder9))
(cloned-from (_Engine1)))

KM> (showme _Cylinder9)
(_Cylinder9 has
(parts-of (_Engine8))
(has-part-of (_Engine8))
(instance-of (Cylinder))
(color (*black))
(cloned-from (_Cylinder1)))

Reply all
Reply to author
Forward
0 new messages