Next: Modify Macros, Up: Generalized Variables [Contents][Index]
Several standard (e.g., car
) and Emacs-specific
(e.g., window-point
) Lisp functions are setf
-able by default.
This package defines setf
handlers for several additional functions:
cl-rest cl-subseq cl-get cl-getf cl-caaar…cl-cddddr cl-first…cl-tenth
Note that for cl-getf
(as for nthcdr
), the list argument
of the function must itself be a valid place form.
setf
is applied to the resulting form.
The setf
macro takes care to evaluate all subforms in
the proper left-to-right order; for example,
(setf (aref vec (cl-incf i)) i)
looks like it will evaluate (cl-incf i)
exactly once, before the
following access to i
; the setf
expander will insert
temporary variables as necessary to ensure that it does in fact work
this way no matter what setf-method is defined for aref
.
(In this case, aset
would be used and no such steps would
be necessary since aset
takes its arguments in a convenient
order.)
However, if the place form is a macro which explicitly evaluates its arguments in an unusual order, this unusual order will be preserved. Adapting an example from Steele, given
(defmacro wrong-order (x y) (list 'aref y x))
the form (setf (wrong-order a b) 17)
will
evaluate b first, then a, just as in an actual call
to wrong-order
.