From: Kaz K. <ka...@as...> - 2003-08-12 17:21:27
|
On Mon, 11 Aug 2003, Thomas Torsney-Weir wrote: > Date: Mon, 11 Aug 2003 22:21:36 -0400 > From: Thomas Torsney-Weir <tor...@ge...> > To: cli...@li... > Subject: [clisp-list] macro problem > > This is really a general lisp question, but anyway. > > Can someone explain why macros can't destructure lists of more than 2 > items? So I can't do this: > > [148]> (defmacro broken-mac ((a b c)) `(,a ,b ,c)) > BROKEN-MAC > [149]> (broken-mac '(1 2 3)) > *** - EVAL: too many parameters for special operator QUOTE: (QUOTE (1 2 > 3) NIL) This is equivalent to (broken-mac (quote (1 2 3))). What's broken here, I think, is that the destructuring error is not signaled. There are only two parameters given for the nested lambda list (a b c). > But this works? > [151]> (defmacro ok-mac ((a b)) `(,a ,b)) > OK-MAC > [152]> (ok-mac '(1 2)) > (1 2) This is just (ok-mac (quote (1 2))) So the A parameter is the symbol QUOTE, and the B paramter is the list (1 2). The replacement form is therefore (QUOTE (1 2)). The (quote (1 2)) list is passed to the macro without being evaluated. > It doesn't make any sense to me. I wrote a version as a function with > destructuring-bind and that works as expected. But functions are different. The argument expressions in a function call are evaluated, so if you have an OK-FUNC instead of OK-MAC and you call it like (ok-mac '(1 2)) then it just gets one argument---the list (1 2). Moreover, the return value is not substituted into the program and re-evaluated. -- Meta-CVS: directory structure versioning; versioned symbolic links; versioned execute permission; versioned property lists; easy branching and merging and third party code tracking; all implemented over the standard CVS command line client -- http://freshmeat.net/projects/mcvs |