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

Re: setq with memory



> You should use a macro like this:
> 
> (defmacro my-setq (&whole expr var val)
>    (push expr *mem*)
>    `(SETQ VAR ,val))
> 
> This does more or less what you want with that ugly quoting.

A more general version of this macro, and one that illustrates
slightly better programming style (but only slightly) goes:

(defmacro record-eval (expression)
  `(progn (push ',expression *mem*)
          ,expression))

This is a more general way of accomplishing the same thing because
it allows you to record any expression for later playback, not just
setq.  It also does the recording at eval time rather than macro
expansion time, which is probably closer to what Dr. Olmi had in
mind.

In general, though, you are almost certainly pursuing a poor program
design if you have to resort to tricks like these, especially if you
are a Lisp beginner.  Using EVAL is almost always a bad idea.  Why
not just define a function to do whatever actions you want to repeat?

Erann Gat
gat@jpl.nasa.gov