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 ······@eurocom.od.ua
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
"Vladimir V. Zolotych" <······@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.