| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
9.8.5 Accessing Slots
Any slot, regardless of its allocation, can be queried, referenced and set using the following four primitive procedures.
- primitive procedure: slot-exists? obj slot-name
Return
#tif obj has a slot with name slot-name, otherwise#f.
- primitive procedure: slot-bound? obj slot-name
Return
#tif the slot named slot-name in obj has a value, otherwise#f.slot-bound?calls the generic functionslot-missingif obj does not have a slot called slot-name (see section slot-missing).
- primitive procedure: slot-ref obj slot-name
Return the value of the slot named slot-name in obj.
slot-refcalls the generic functionslot-missingif obj does not have a slot called slot-name (see section slot-missing).slot-refcalls the generic functionslot-unboundif the named slot in obj does not have a value (see section slot-unbound).
- primitive procedure: slot-set! obj slot-name value
Set the value of the slot named slot-name in obj to value.
slot-set!calls the generic functionslot-missingif obj does not have a slot called slot-name (see section slot-missing).
GOOPS stores information about slots in classes. Internally,
all of these procedures work by looking up the slot definition for the
slot named slot-name in the class (class-of
obj), and then using the slot definition’s “getter” and
“setter” closures to get and set the slot value.
The next four procedures differ from the previous ones in that they take
the class as an explicit argument, rather than assuming
(class-of obj). Therefore they allow you to apply the
“getter” and “setter” closures of a slot definition in one class to
an instance of a different class.
- primitive procedure: slot-exists-using-class? class obj slot-name
Return
#tif class has a slot definition for a slot with name slot-name, otherwise#f.
- primitive procedure: slot-bound-using-class? class obj slot-name
Return
#tif applyingslot-ref-using-classto the same arguments would call the generic functionslot-unbound, otherwise#f.slot-bound-using-class?calls the generic functionslot-missingif class does not have a slot definition for a slot called slot-name (see section slot-missing).
- primitive procedure: slot-ref-using-class class obj slot-name
Apply the “getter” closure for the slot named slot-name in class to obj, and return its result.
slot-ref-using-classcalls the generic functionslot-missingif class does not have a slot definition for a slot called slot-name (see section slot-missing).slot-ref-using-classcalls the generic functionslot-unboundif the application of the “getter” closure to obj returns an unbound value (see section slot-unbound).
- primitive procedure: slot-set-using-class! class obj slot-name value
Apply the “setter” closure for the slot named slot-name in class to obj and value.
slot-set-using-class!calls the generic functionslot-missingif class does not have a slot definition for a slot called slot-name (see section slot-missing).
Slots whose allocation is per-class rather than per-instance can be referenced and set without needing to specify any particular instance.
- procedure: class-slot-ref class slot-name
Return the value of the slot named slot-name in class class. The named slot must have
#:classor#:each-subclassallocation (see section allocation).If there is no such slot with
#:classor#:each-subclassallocation,class-slot-refcalls theslot-missinggeneric function with arguments class and slot-name. Otherwise, if the slot value is unbound,class-slot-refcalls theslot-unboundgeneric function, with the same arguments.
- procedure: class-slot-set! class slot-name value
Set the value of the slot named slot-name in class class to value. The named slot must have
#:classor#:each-subclassallocation (see section allocation).If there is no such slot with
#:classor#:each-subclassallocation,class-slot-refcalls theslot-missinggeneric function with arguments class and slot-name.
When a slot-ref or slot-set! call specifies a non-existent
slot name, or tries to reference a slot whose value is unbound, GOOPS
calls one of the following generic functions.
- generic: slot-missing
- method: slot-missing (class <class>) slot-name
- method: slot-missing (class <class>) (object <object>) slot-name
- method: slot-missing (class <class>) (object <object>) slot-name value
When an application attempts to reference or set a class or instance slot by name, and the slot name is invalid for the specified class or object, GOOPS calls the
slot-missinggeneric function.The default methods all call
goops-errorwith an appropriate message.
- generic: slot-unbound
- method: slot-unbound (object <object>)
- method: slot-unbound (class <class>) slot-name
- method: slot-unbound (class <class>) (object <object>) slot-name
When an application attempts to reference a class or instance slot, and the slot’s value is unbound, GOOPS calls the
slot-unboundgeneric function.The default methods all call
goops-errorwith an appropriate message.
| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on February 3, 2012 using texi2html 5.0.
