next up previous

9.3.3.4 Access Facet

There are three types of access facets which can be specified for a slot: read-write, read-only, and initialize-only. The read-write facet is the default and says that a slot can be both written and read. The read-only facet says the slot can only be read; the only way to set this slot is with default facets in the class definition. The initialize-only facet is like read-only except that the slot can also be set by slot overrides in a make-instance call (see section 9.6.1) and init message-handlers (see section 9.4). These privileges apply to indirect access via messages as well as direct access within message-handler bodies (see section 9.4). Note: a read-only slot that has a static default value will implicitly have the shared storage facet.

Example

CLIPS> (clear)
CLIPS>
(defclass A (is-a USER)
    (role concrete)
    (slot foo (create-accessor write)
            (access read-write))
    (slot bar (access read-only)
            (default abc))
    (slot woz (create-accessor write)
            (access initialize-only)))
CLIPS>
(defmessage-handler A put-bar (?value)
    (dynamic-put (sym-cat bar) ?value))
CLIPS> (make-instance a of A (bar 34))
[MSGFUN3] bar slot in [a] of A: write access denied.
[PRCCODE4] Execution halted during the actions of message-handler put-bar primary in class A
FALSE
CLIPS> (make-instance a of A (foo 34) (woz 65))
[a]
CLIPS> (send [a] put-bar 1)
[MSGFUN3] bar slot in [a] of A: write access denied.
[PRCCODE4] Execution halted during the actions of message-handler put-bar primary in class A
FALSE
CLIPS> (send [a] put-woz 1)
[MSGFUN3] woz slot in [a] of A: write access denied.
[PRCCODE4] Execution halted during the actions of message-handler put-bar primary in class A
FALSE
CLIPS> (send [a] print)
[a] of A
(foo 34)
(bar abc)
(woz 65)
CLIPS>


next up previous