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

Re: setq with memory



	Hi,


> I am a lisp beginner, so my question could have a straightforward answer.
>
> I am trying to implement a simple function MY-SETQ which does exactly what
> SETQ does, and records in a list *MEM* the actions done. The objective is to
> have the possibility of seeing (and executing, by MAPCAR and EVAL) the
> assignements done.
>
> I have implemented MY-SETQ as follows:
>
> (defun my-setq (x y)
>      (set x (eval y))
>      (setq *MEM* (cons (list 'setq x y) *MEM*)))
> After an inizialization of *MEM* to nil, the commands look like these:
>
> (my-setq 'x ''abc)
> (my-setq 'y ''(sin 1.2345))
>
> and *MEM* is, in the above case: ((setq y '(sin 1.2345)) (setq x 'abc))
>
> so that, for example, (mapcar 'eval *MEM*) does the required re-assignement.
>
> The question is: how can I implement MY-SETQ such that the arguments are
> written in a more "natural" way, to say:  (my-setq  x  'abc) ?
>
> Any suggestion will be greatly appreciated.
>

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.


Q: What for do you need that?

--
----------------------------------------------------------------------
Roger Kehr  	kehr@iti.informatik.th-darmstadt.de
----------------------------------------------------------------------