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

writing macros

4 views
Skip to first unread message

Vladimir V. Zolotych

unread,
Sep 22, 2001, 10:54:01 AM9/22/01
to
Hi

Consider the following (idiom ?):

(defmacro foo ((var &rest args) &body body)
`(let ((,var (establish ,args)))
(unwind-protect
(let ((,var ,var)) ,@body)
(destroy ,var))))

What will I lose if write (progn ,@body) instead of
(let ((,var ,var)) ,@body) ?

Thanks in advance

--
Vladimir Zolotych gsm...@eurocom.od.ua

Tim Moore

unread,
Sep 22, 2001, 1:11:37 PM9/22/01
to
On Sat, 22 Sep 2001, Vladimir V. Zolotych wrote:

> Hi
>
> Consider the following (idiom ?):
>
> (defmacro foo ((var &rest args) &body body)
> `(let ((,var (establish ,args)))
> (unwind-protect
> (let ((,var ,var)) ,@body)
> (destroy ,var))))
>
> What will I lose if write (progn ,@body) instead of
> (let ((,var ,var)) ,@body) ?
>

Are you worried about someone setting ,var in the body of the macro? If
so, then yeah, you'll lose without the let.

Tim


Kent M Pitman

unread,
Sep 22, 2001, 1:48:24 PM9/22/01
to
"Vladimir V. Zolotych" <gsm...@eurocom.od.ua> writes:

> Consider the following (idiom ?):
>
> (defmacro foo ((var &rest args) &body body)
> `(let ((,var (establish ,args)))

This should almost certainly be ,@args

> (unwind-protect
> (let ((,var ,var)) ,@body)
> (destroy ,var))))
>
> What will I lose if write (progn ,@body) instead of
> (let ((,var ,var)) ,@body) ?

Reliability.

Since VAR is supplied by the user, you have the risk that the
user can do

(foo (zing)
(blah blah)
(setq zing nil))

and that the value of zing when you go to destroy it will be NIL.

Probably even in that case you should do
(if ,var (destroy ,var))
unless you have specially specialized DESTROY for NIL or whatever
rescue value you want to choose. You should definitely document
the rescue value since there are still illegal values.

Vladimir V. Zolotych

unread,
Sep 22, 2001, 3:32:19 PM9/22/01
to
Exhaustive answer. Thanks.

Vladimir

gsmith.vcf
0 new messages