[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Pushing defmacro hard: destructured &KEY bindings
CLtL pages 149-151 mentions destructuring within lambda list keywords
for defmacro, but don't give enough examples for users to know what is
expected to work and what isn't. Specifically, it does give examples of
destructuring &OPTIONAL, but doesn't say &REST may not be destructured
(it doesn't at first glance make much sense, but program writing
programs may generate it, and it may be a good way to do some further
destructuring) and it is silent on &KEY. For example, is the following
legal?
(defmacro funny (&key
((:two-elements (x1 x2)) '(two-1 two-2))
((:three-elements (y1 y2 y3)) '(three-1 three-2 three-3))
((:two-or-three (z1 z2 &optional (z3 'zee-three))) '(sis boom bah)))
(list x1 x2 y1 y2 y3 z1 z2 z3))
(funny :three-elements (foo bar baz)
:two-elements (Common Lisp)
:two-or-three (tea coffee))
==> (Common Lisp foo bar baz tea coffee zee-three)
And is this legal?
(defmacro bone (a b &optional c &rest (&whole d &optional e f g &rest h))
(list a b c d e f g h))