(defmacro test (l)
`(progn
(format t "~&l=~s~%" ,l)))
(test '(1 2 3)) ; => l=(1 2 3)
(let ((lst '(4 5 6))) (test lst)) ; => l=(4 5 6)
But in this second example, it doesn't. Why is that?
(defmacro test2 (&key (l '(1 2 3)))
`(progn
(format t "~&l=~s~%" ,l)))
(let ((lst '(4 5 6))) (test2 :l lst)) ; => l=(4 5 6)
(test2 '(1 2 3))
1 compiler notes:
ex.lisp:15:1:
error:
(during macroexpansion of (TEST2 '(1 2 ...)))
error while parsing arguments to DEFMACRO TEST2:
odd number of elements in keyword/value list: ('(1 2 3))
Compilation failed.
There is something basic I don't understand here.
--jkc
> I'm puzzling over this. In this macro I can enter a list argument in
> one of two ways and it works just fine:
>
> (defmacro test (l)
> `(progn
> (format t "~&l=~s~%" ,l)))
>
> (test '(1 2 3)) ; => l=(1 2 3)
> (let ((lst '(4 5 6))) (test lst)) ; => l=(4 5 6)
>
>
> But in this second example, it doesn't. Why is that?
>
> (defmacro test2 (&key (l '(1 2 3)))
> `(progn
> (format t "~&l=~s~%" ,l)))
>
> (let ((lst '(4 5 6))) (test2 :l lst)) ; => l=(4 5 6)
> (test2 '(1 2 3))
(test2 :L '(1 2 3))
> 1 compiler notes:
>
> ex.lisp:15:1:
> error:
> (during macroexpansion of (TEST2 '(1 2 ...)))
> error while parsing arguments to DEFMACRO TEST2:
> odd number of elements in keyword/value list: ('(1 2 3))
>
> Compilation failed.
>
> There is something basic I don't understand here.
Yes. The basic thing you missed in this case is DO NOT USE ONE-LETTER
VARIABLES!
If you have written: (defmacro test2 (&key (DATA-TO-DISPLAY '(1 2 3))) ...)
then you would have noticed that something was wrong in:
(test2 '(1 2 3)) ; vs.
(test2 :data-to-display my-data)
--
__Pascal Bourguignon__
And to make Kenny happy, read:
http://smuglispweeny.blogspot.com/2008/07/aa-bb-cc-and-dd.html
--
__Pascal Bourguignon__
I can't believe I didn't notice that.
Sorry about the noise.
--jkc
> And to make Kenny happy, read:
>
> http://smuglispweeny.blogspot.com/2008/07/aa-bb-cc-and-dd.html
>
Now that's an amusing read.
--jkc
... and - I'm chagrined to say - after applying its philosophy to a
project I've been working on I discovered several bugs I didn't know
about. I'm a convert.
--jkc