[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: setq with memory
- To: clisp-list@ma2s2.mathematik.uni-karlsruhe.de
- Subject: Re: setq with memory
- From: Roger Kehr <kehr@iti.informatik.th-darmstadt.de>
- Date: Wed, 26 Jun 1996 15:54:05 +0200 (MESZ)
- In-reply-to: <9606260837.AA10312@iroe.iroe.fi.cnr.it> from "Roberto Olmi" at Jun 26, 96 11:19:21 am
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
----------------------------------------------------------------------