next up previous

9.3.3.9 Create-Accessor Facet

In CLIPS 5.1, implicit slot-accessor message-handlers were created for every slot. This not true in CLIPS 6.0. The user must define their own message-handlers for reading and writing the slot. This was done because in most cases the accessors were not required; explicit message-handlers attached to the class of the slot directly accessed the slot anyway. However, the create-accessor facet instructs CLIPS to automatically create explicit message-handlers for reading and/or writing a slot. By default, no accessors are created. While these message-handlers are real message-handlers and can be manipulated as such, they have no pretty-print form and cannot be directly modified by the user.

If the value read is specified for the facet, CLIPS creates the following message-handler:

(defmessage-handler <class> get-<slot-name> primary ()
    ?self:<slot-name>)

If the value write is specified for the facet, CLIPS creates the following message-handler for single-field slots:

(defmessage-handler <class> put-<slot-name> primary (?value)
    (bind ?self:<slot-name> ?value)

or the following message-handler for multifield slots:

(defmessage-handler <class> put-<slot-name> primary ($?value)
    (bind ?self:<slot-name> ?value)

If the value read-write is specified for the facet, both the get and one of the put message-handlers are created.

If accessors are required that do not use static slot references (see sections 9.4.2, 9.6.3 and 9.6.4), then user must define them explicitly with the defmessage-handler construct.

Example

CLIPS> (clear)
CLIPS>
(defclass A (is-a USER)
  (role concrete)
  (slot foo (create-accessor write))
  (slot bar))
CLIPS> (make-instance a of A (foo 36))
[a]
CLIPS> (make-instance b of A (bar 45))
[MSGFUN1] No applicable primary message-handlers found for put-bar.
FALSE
CLIPS>


next up previous