next up previous

9.6.1.1 Definstances Construct

Similar to deffacts, the definstances construct allows the specification of instances which will be created every time the reset command is executed. On every reset all current instances receive a delete message, and the equivalent of a make-instance function call is made for every instance specified in definstances constructs.

Syntax

(definstances <definstances-name> [active] [<comment>]
    <instance-template>*)
<instance-template> ::= (<instance-definition>)

A definstances cannot use classes which have not been previously defined. The instances of a definstances are created in order, and if any individual creation fails, the remainder of the definstances will be aborted. Normally, definstances just use the make-instance function (which means delayed Rete activity) to create the instances. However, if this is not desired,then the active keyword can be specified after the definstances name so that the active-make-instance function will be used.

Example

CLIPS> (clear)
CLIPS>
(defclass A (is-a USER) (role concrete)
     (slot x (create-accessor write) (default 1)))
CLIPS>
(definstances A-OBJECTS
     (a1 of A)
   (of A (x 65)))
CLIPS> (watch instances)
CLIPS> (reset)
==> instance [initial-object] of INITIAL-OBJECT
==> instance [a1] of A
==> instance [gen1] of A
CLIPS> (reset)
<== instance [initial-object] of INITIAL-OBJECT
<== instance [a1] of A
<== instance [gen1] of A
==> instance [initial-object] of INITIAL-OBJECT
==> instance [a1] of A
==> instance [gen2] of A
CLIPS> (unwatch instances)
CLIPS>

Upon startup and after a clear command, CLIPS automatically constructs the following definstances.

(definstances initial-object
   (initial-object of INITIAL-OBJECT))

The class INITIAL-OBJECT is a predefined system class that is a direct subclass of USER.

(defclass INITIAL-OBJECT
   (is-a USER)
   (role concrete)
   (pattern-match reactive))

The initial-object definstances and the INITIAL-OBJECT class are only defined if both the object system and defrules are enabled (see section 2 of the Advanced Programming Guide). The INITIAL-OBJECT class cannot be deleted, but the initial-object definstances can. See section 5.4.9 for details on default patterns which pattern-match against the initial-object instance.


next up previous