Four functions are provided for duplicating instances. These functions allow instance duplication and slot updates to be performed in blocks without requiring a series of put- messages. Each of these functions return the instance-name of the new duplicated instance if successful, otherwise the symbol FALSE is returned.
Each of the duplicate functions can optionally specify the name of the instance to which the old instance will be copied. If the name is not specified, the function will generate the name using the (gensym*) function. If the target instance already exists, it will be deleted directly or with a delete message depending on which function was called.
The duplicate-instance function uses the direct-duplicate message to change the values of the instance. Object pattern-matching is delayed until all of the slot modifications have been performed.
Syntax
(duplicate-instance <instance> [to <instancename>] <slot-override>*)
Example
CLIPS> (clear) CLIPS> (setgen 1) 1 CLIPS> (defclass A (is-a USER) (role concrete) (slot foo (create-accessor write)) (slot bar (create-accessor write))) CLIPS> (make-instance a of A (foo 0) (bar 4)) [a] CLIPS> (watch all) CLIPS> (duplicate-instance a) MSG >> direct-duplicate ED:1 (<Instance-a> [gen1] <Pointer-00000000>) HND >> direct-duplicate primary in class USER ED:1 (<Instance-a> [gen1] <Pointer-00000000>) ==> instance [gen1] of A ::= local slot foo in instance gen1 <- 0 ::= local slot bar in instance gen1 <- 4 HND << direct-duplicate primary in class USER ED:1 (<Instance-a> [gen1] <Pointer-00000000>) MSG << direct-duplicate ED:1 (<Instance-a> [gen1] <Pointer-00000000>) [gen1] CLIPS> (unwatch all) CLIPS>
The active-duplicate-instance function uses the direct-duplicate message to change the values of the instance. Object pattern-matching occurs as slot modifications are being performed.
Syntax
(active-duplicate-instance <instance> [to <instancename>] <slot-override>*)
The message-duplicate-instance function uses the message-duplicate message to change the values of the instance. Object pattern-matching is delayed until all of the slot modifications have been performed.
Syntax
(message-duplicate-instance <instance> [to <instancename>] <slot-override>*)
Example
CLIPS> (clear) CLIPS> (defclass A (is-a USER) (role concrete) (slot foo (create-accessor write)) (slot bar (create-accessor write))) CLIPS> (make-instance a of A (foo 0) (bar 4)) [a] CLIPS> (make-instance b of A) [b] CLIPS> (watch all) CLIPS> (message-duplicate-instance a to b (bar 6)) MSG >> message-duplicate ED:1 (<Instance-a> [b] <Pointer-009F04A0>) HND >> message-duplicate primary in class USER ED:1 (<Instance-a> [b] <Pointer-009F04A0>) MSG >> delete ED:2 (<Instance-b>) HND >> delete primary in class USER ED:2 (<Instance-b>) <== instance [b] of A HND << delete primary in class USER ED:2 (<Stale Instance-b>) MSG << delete ED:2 (<Stale Instance-b>) ==> instance [b] of A MSG >> put-bar ED:2 (<Instance-b> 6) HND >> put-bar primary in class A ED:2 (<Instance-b> 6) ::= local slot bar in instance b <- 6 HND << put-bar primary in class A ED:2 (<Instance-b> 6) MSG << put-bar ED:2 (<Instance-b> 6) MSG >> put-foo ED:2 (<Instance-b> 0) HND >> put-foo primary in class A ED:2 (<Instance-b> 0) ::= local slot foo in instance b <- 0 HND << put-foo primary in class A ED:2 (<Instance-b> 0) MSG << put-foo ED:2 (<Instance-b> 0) MSG >> init ED:2 (<Instance-b>) HND >> init primary in class USER ED:2 (<Instance-b>) HND << init primary in class USER ED:2 (<Instance-b>) MSG << init ED:2 (<Instance-b>) HND << message-duplicate primary in class USER ED:1 (<Instance-a> [b] <Pointer-009F04A0>) MSG << message-duplicate ED:1 (<Instance-a> [b] <Pointer-009F04A0>) [b] CLIPS> (unwatch all) CLIPS>
The active-message-duplicate-instance function uses the message-duplicate message to change the values of the instance. Object pattern-matching occurs as slot modifications are being performed.
Syntax
(active-message-duplicate-instance <instance> [to <instancename>] <slot-override>*)