Setters implement generalized locations for objects
associated with some sort of mutable state. A getter operation
retrieves a value from a generalized location and the corresponding
setter operation stores a value into the location. Only the getter is
named – the setter is specified by a procedure call as below. (Dylan
uses special syntax.) Typically, but not necessarily, getters are
access operations to extract values from Yasos objects (see Yasos).
Several setters are predefined, corresponding to getters car,
cdr, string-ref and vector-ref e.g., (setter
car) is equivalent to set-car!.
This implementation of setters is similar to that in Dylan(TM)
(Dylan: An object-oriented dynamic language, Apple Computer
Eastern Research and Technology). Common LISP provides similar
facilities through setf.
Returns the setter for the procedure getter. E.g., since
string-refis the getter corresponding to a setter which is actuallystring-set!:(define foo "foo") ((setter string-ref) foo 0 #\F) ; set element 0 of foo foo ⇒ "Foo"
If place is a variable name,
setis equivalent toset!. Otherwise, place must have the form of a procedure call, where the procedure name refers to a getter and the call indicates an accessible generalized location, i.e., the call would return a value. The return value ofsetis usually unspecified unless used with a setter whose definition guarantees to return a useful value.(set (string-ref foo 2) #\O) ; generalized location with getter foo ⇒ "FoO" (set foo "foo") ; like set! foo ⇒ "foo"
Add procedures getter and setter to the (inaccessible) list of valid setter/getter pairs. setter implements the store operation corresponding to the getter access operation for the relevant state. The return value is unspecified.