LISA 2.0

5 December, 2002

Auto Notification

For Common Lisps with complete, or mostly complete, MOP implementations, LISA offers an experimental feature called “auto notification”. This mechanism may be used to monitor changes to CLOS instances in working memory that occur outside of LISA (i.e. somewhere else in the application, and not via the modify macro). Normally, LISA must be explicitly told about these changes via the function lisa:mark-instance-as-changed; when an application alters the contents of an instance’s slots, it informs LISA about the changes so the inference engine can maintain the consistency of working memory. Auto Notification obviates this requirement; LISA hooks into the MOP slot access protocol and notices slot changes without application intervention. Like just about anything worthwhile, however, the benefits of this feature come at a small price. Any user-defined class participating in Auto Notification must, at a minimum, have as its metaclass lisa:standard-kb-class. For example:

(defclass frodo ()
  ((name :accessor frodo-name))
  (:metaclass lisa:standard-kb-class))

There may also be implementation-specific needs that further constrain users of Auto Notification. In general, however, the use of the aforementioned metaclass is all that’s required.

As of this writing, Auto Notification has been tested with Allegro Common Lisp 6.2 and Lispworks 4.2. CLISP does not have a MOP implementation of sufficient depth, and I have not yet attempted a version for CMUCL (I would welcome a submission). Regarding the two commercial Common Lisps supported by LISA, their implementations of Auto Notification are described below, listing any additional requirements beyond the use of lisa:standard-kb-class.

ACL 6.2

LISA implements Auto Notification for Allegro by adding an around method on make-instance, and an after method on (setf slot-value-using-class). Whether an application alters a slot via its writer method or a direct invocation of (setf slot-value), LISA notices the change and reacts accordingly. Note carefully, however, that I’ve only tested this with the default compiler optimization settings, under version 6.2. Due to my experience with Lispworks (see below), it remains to be seen whether the current implementation for ACL will hold.

Lispworks 4.2

Auto Notification for Lispworks is a bit more complicated than the ACL version, because the Lispworks compiler appears to optimize methods containing calls to slot-value, such that the standard MOP slot access protocol is bypassed. Therefore, the implementation used for ACL won’t work here. Instead, LISA must iterate through the writer methods of all classes whose metaclass is lisa:standard-kb-class and attach special after methods on their generic functions; these special methods respond to slot changes and notify LISA accordingly. To create these methods, LISA installs an after method on initialize-instance, specialized on lisa:standard-kb-class, that does most of the work. As a result, applications wishing to use Auto Notification with Lispworks must ensure that all class slots that might be referenced by rules have corresponding writer methods. Altering a slot’s contents by direct calls to (setf slot-value) will bypass Auto Notification and corrupt the inference engine’s working memory. This constraint is in addition to the metaclass requirement described previously.