All Manuals > KnowledgeWorks and Prolog User Guide > 4 Objects


4.1 CLOS objects

A KnowledgeWorks CLOS class may not have a class name which coincides with any rule, context or KnowledgeWorks structure (See KnowledgeWorks Structures). KnowledgeWorks CLOS classes fall into one of two categories, either unnamed or named. Named objects can be given a name (or they use a default name) and can be referred to by name. Otherwise, named and unnamed objects have equivalent functionality. CLOS objects may be made by the Common Lisp function make-instance, taking the same arguments. An unbound slot will return :unbound until set.

Name clashes are arbitrated by *signal-kb-name-clash* and signal an error by default. See the reference manual page.

4.1.1 Unnamed Classes

Unnamed classes may be defined by the macro def-kb-class which takes the same arguments as the defclass macro. It is identical to using defclass and supplying the KnowledgeWorks mixin standard-kb-object if none of the superclasses already contains it. The function make-instance may be used to create instances of the class.

4.1.2 Named Classes

A named KnowledgeWorks CLOS class is defined by the macro def-named-kb-class which is syntactically identical to the Common Lisp defclass macro, and semantically identical with the exception that it adds a KnowledgeWorks mixin class named-kb-object if none of the superclasses already contains it, and makes the default name for the objects be a symbol generated from the class name. Classes defined by def-named-kb-class contain a name slot which those defined by def-kb-class do not.

The function make-instance can be given the initialization argument :kb-name to specify a name. If not specified, a default name is generated from the name of the class. All names must be distinct as regarded by eq. The function

(get-kb-object <name>)

retrieves the instance from its name. The function

(kb-name <object>)

returns the name of the given object. Examples
(def-named-kb-class truck ()
     ((location :initarg :location)
      (destination :initarg :destination)))
(make-instance 'truck 
               :kb-name 'ford1
               :location 'Cambridge)

creates the instance #<KB-OBJECT FORD1>.

(make-instance 'truck :location 'London)

creates the instance #<KB-OBJECT TRUCK123>, and

(get-kb-object 'ford1)

returns #<KB-OBJECT FORD1> and

(kb-name (get-kb-object 'ford1))

returns FORD1. The class definition

(defclass truck (named-kb-object) ...)

would have been identical except that the second truck would have been given a name such as OBJECT345 rather than TRUCK123 (as def-named-kb-class overrides the inherited initform for the kb-name slot (gentemp "OBJECT") with a more specific one (gentemp <class-name>)).

KnowledgeWorks and Prolog User Guide (Macintosh version) - 24 Mar 2017