All Manuals > KnowledgeWorks and Prolog User Guide > 6 Advanced Topics > 6.2 Optimization > 6.2.1 Forward Chaining

NextPrevUpTopContentsIndex KnowledgeWorks Structures

A CLOS class may be replaced by a structure for increased speed when all the power of CLOS is not needed. Within the rule interpreter the structure behaves like a CLOS class which:

A KnowledgeWorks structure is defined by the macro

(def-kb-struct <class-spec> <slot-spec>*)

where the arguments are the same as for defstruct except that in <class-spec> only the options :include and :print-function are allowed. A structure may only be included in a KnowledgeWorks structure if it too is a KnowledgeWorks structure defined by def-kb-struct . All the functions normally provided by defstruct (accessors, a predicate etc.) are generated. An instance of the structure class may be created by the generic function

(make-instance <class-name> 
             {<slot-specifier> <value>}*)

where <slot-specifier> is the keyword version of the slot name, as with any structures, and <value> is the value the slot is to take, otherwise defaulting to the value specified in the def-kb-struct form. If created from Lisp by any means other than make-instance (for example, by the automatically defined make-<structure-name> constructor), the inference engine will not know about the structure.

Once created, structures must not be modified directly from Lisp as this will corrupt the state of the forward chaining inference engine. For example:

(def-kb-struct train position speed)
(def-kb-struct signal position colour)
(make-instance 'train :position 0 :speed 80)
(make-instance 'signal :position 10 :colour 'red)

defines KnowledgeWorks structures for trains and signals and makes an instance of each. Note that they are not fully-fledged CLOS objects but are analogous to working memory elements in OPS5.

KnowledgeWorks and Prolog User Guide (Windows version) - 6 Dec 2011