[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


In reference to Bob Sasseen's idea of a Modifyf macro:
(Modifyf (CAR x) + 3) <-> (SETF (CAR x) (+ (CAR x) 3))

We have implemented a different, but similar macro:
(DEFMACRO Self (place function-or-form) ...)
Self can take a place and a single function to modify the place with:
(Self object CDDDR) <-> (SETF object (CDDDR object))

If function-or-form is a form, not the name of a function, then Self replaces
the symbol :self with the place:

(Self (Structure-Thing struc) (DELETE NIL :self)) <->
   (SETF (Structure-Thing struc) (DELETE NIL (Structure-Thing struc)))

If place is of type (Function1 (Function2 ...)), Self takes care that
(Function2 ...) is only evaled once:

(Self (CAR (SECOND x)) 1+) <->
   (LET ((#:|(second x)| (SECOND x)))
      (SETF (CAR #:|(second x)|) (1+ (CAR #:|(second x)|))))

I think this is more generally useful than MODIFYF because the
modified field need not be the first argument of the modifier.

I don't feel that Self, Modifyf, or any similar modify macro
should be made part of CL until questions such as robustness vs. readability
can be resolved.

David Loewenstern
Naval Air Development Center
code 7013
Warminster, PA 18974-5000