Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

printing the name of a var. in a macro^

0 views
Skip to first unread message

Christopher J. Vogt

unread,
May 15, 2000, 3:00:00 AM5/15/00
to
kp gores wrote:
>
> hi,
>
> i want a macro to set variables to values. it should print what it does,
> eg. (setv a 42) --> setting a
>
> this does not work with the following code:
>
> (defmacro setv (v value)
> `(progn (format t "setting ~S~% to ~S" v ,value)
> (setf ,v ,value)))

Try this:
(format t "setting ~S~% to ~S" ',v ,value)
^^
-------------------------------||

>
> how can i print the variables name?
> ciao
> kp
>
> --
> superegos talker

Barry Margolin

unread,
May 15, 2000, 3:00:00 AM5/15/00
to
In article <gores-2B386B....@news.uni-ulm.de>,
kp gores <go...@sip.medizin.uni-ulm.de> wrote:

>In article <391FFB73...@computer.org>, vo...@home.com wrote:
>
>> kp gores wrote:
>> >
>> > hi,
>> >
>> > i want a macro to set variables to values. it should print what it does,
>> > eg. (setv a 42) --> setting a
>> >
>> > this does not work with the following code:
>> >
>> > (defmacro setv (v value)
>> > `(progn (format t "setting ~S~% to ~S" v ,value)
>> > (setf ,v ,value)))
>>
>> Try this:
>> (format t "setting ~S~% to ~S" ',v ,value)
>> ^^
>
>thank you. that easy.. :-)

Beware of what this will do if the VALUE form has side effects. E.g. take
a look at (macroexpand '(setf a (incf b))). Solving the problem is an
exercise for the reader.

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

Rob Warnock

unread,
May 17, 2000, 3:00:00 AM5/17/00
to
Barry Margolin <bar...@genuity.net> wrote:
+---------------

| >> > (defmacro setv (v value)
| >> > `(progn (format t "setting ~S~% to ~S" v ,value)
| >> > (setf ,v ,value)))
| >> Try this:
| >> (format t "setting ~S~% to ~S" ',v ,value)
| >
| >thank you. that easy.. :-)
|
| Beware of what this will do if the VALUE form has side effects. E.g. take
| a look at (macroexpand '(setf a (incf b))). Solving the problem is an
| exercise for the reader.
+---------------

Didn't you mean, "LET the reader beware"...? ;-} ;-}

(Sorry, couldn't resist.)


-Rob

-----
Rob Warnock, 41L-955 rp...@sgi.com
Applied Networking http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
1600 Amphitheatre Pkwy. PP-ASEL-IA
Mountain View, CA 94043

0 new messages