[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
&whole cum destructuring
From: Steve Bacher (C.S.Draper Lab)
In-reply-to: David C. Plummer <DCP at SCRC-QUABBIN>
> (defmacro with-open-file ((&whole stuff var filename &rest keys)
> &body body)
> ...
> (warn "The first form of with-open-file, ~S, is malformed." stuff)
> ...)
How useful is this really? It depends on how destructuring is
implemented. The following cases are possible, given passing a badly
formed argument (e.g. a symbol FOO) as arg 1 to with-open-file:
(1) The prologue code that destructures the argument attempts to
destructure FOO and blows up (or causes an error trap).
(2) The prologue code that destructures the argument detects the
invalid actual parameter and signals an error, something like
"Error: Unable to destructure FOO into (var filename &rest keys)
in macro WITH-OPEN-FILE"
(3) The prologue code that destructures the argument detects the
invalid actual parameter and assigns some default value to
var, filename, and keys.
In (1) and (2), the macro expansion function will never get control
in order to tell the user anything about the value of the &whole
argument. In (3), it might not be possible to tell that there is
a problem (except by inspecting the &whole arg, in which case you
can just follow it up with a destructuring LET).
I know what you'll say: "That's just an example, there are other
applications", etc. True, but it seems to me that in most cases
you'll never make it that far in your code unless the value passed was
successfully destructured, and in that case you can easily
"de-destructure" it if you want.
I think that the meaning of &whole at other than "top-level" in a
DEFMACRO lambda list is questionable. I prefer to see nested
destructuring lambda lists as equivalent to "normal" lambda lists
(i.e. without the special DEFMACRO hair). Presumably the lambda list
that DEFMACRO sees at top level gets hacked up into a "true"
lambda list internally, and only the DEFMACRO expander itself knows
about &whole and &env. At least that's one possible
implementation/interpretation.
- SEB