| set! <variable> <expression> | R5RS |
| set! <proc> <arg> ... <expression> | R5RS |
The fisrt form of set! is the R5RS
one. The second corrspond to the
form defined in SRFI-17.
<Expression> is evaluated, and the resulting value is stored in
the location to which <variable> is bound. <Variable> must be bound
either in some region enclosing the set! expression or at top level.
(define x 2)
(+ x 1) => 3
(set! x 4) => unspecified
(+ x 1) => 5
The second form of (set (vector-ref x i) v)
would be equivalent to:
(vector-set! x i v)
Each procedure that may be used as the first operand to (set! (proc arg ...) value)
is equivalent to the call
((setter proc) arg ... value)
The result of the |
| setter proc | R5RS |
Returns the setter associated to a proc. Setters are defined in the SRFI-17
document. A setter proc, can be used in a generalized assignment, as described
in set!. To associate s to the procedure p, use the following form:
(set! (setter p) s)
For instance, we can write
(set! (setter car) set-car!)
The following standard procedures have pre-defined setters: (set! (car x) v) == (set-car! x v)
(set! (cdr x) v) == (set-cdr! x v)
(set! (string-ref x i) v) == (string-set! x i v)
(set! (vector-ref x i) v) == (vector-set! x i v)!
(set! (slot-ref x 'name) v) == (slot-set! x 'name v)
(set! (struct-ref x 'name) v) == (struct-set! x 'name v)
|