-
Notifications
You must be signed in to change notification settings - Fork 0
The Auto Notification Mechanism
For Common Lisps with complete, or mostly complete, MOP implementations, Lisa offers a feature called “auto notification”. This mechanism may be used to monitor changes to CLOS instances in working memory that occur outside of Lisa's control (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 eliminates 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 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.
Auto Notification has been tested with Allegro Common Lisp 6.2, Lispworks 4.2, and SBCL 2.4.11 (just added). CLISP does not have a MOP implementation of sufficient depth, and I have not closely examined other Lisps.
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. SBCL’s requirements are straightforward, very similar to those of CMUCL.
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.
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.
To be written.
If you're using a Lisp implementation that supports Auto Notification, nothing special needs doing. Simply loading Lisa's ASDF will suffice.