| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Sorry if it seems tremendously stupid, but what happens here: [41]> (defmacro foo (bar) (format t "~A" (type-of bar))) FOO [42]> (foo 'quux) CONS NIL so that the symbol becomes a cons? |
|
#2
| |||
| |||
| On Tue, 15 Jan 2008 14:27:16 -0800, Leslie P. Polzer wrote: > Sorry if it seems tremendously stupid, but what happens here: > > [41]> (defmacro foo (bar) (format t "~A" (type-of bar))) FOO > [42]> (foo 'quux) > CONS > NIL > > so that the symbol becomes a cons? Did you mean to do: (defmacro foo (bar) `(format t ... (type-of ,bar))) ? In your original code, bar is not evaluated. Atleast that is my uninformed understanding. Dunno where the cons comes from though. -- Sohail Somani http://uint32t.blogspot.com |
|
#3
| |||
| |||
| "Leslie P. Polzer" <leslie.polzer@gmx.net> writes: > Sorry if it seems tremendously stupid, but what happens here: > > [41]> (defmacro foo (bar) (format t "~A" (type-of bar))) > FOO > [42]> (foo 'quux) > CONS > NIL > > so that the symbol becomes a cons? Did you mean: (defmacro foo (bar) `(format t "~A" (type-of ,bar))) Note the quoting and escaping. Your format routine is going to be called before bar is evaluated. My guess is that bar is (quote quux) at that point. Someone else will probably be here to correct my in a minute. Joost. |
|
#4
| |||
| |||
| On Jan 15, 5:27 pm, "Leslie P. Polzer" <leslie.pol...@gmx.net> wrote: > Sorry if it seems tremendously stupid, but what happens here: > > [41]> (defmacro foo (bar) (format t "~A" (type-of bar))) > FOO > [42]> (foo 'quux) > CONS > NIL > > so that the symbol becomes a cons? foo is a macro, and so it doesn't evaluate its arguments. (foo 'quux) is the same as (foo (quote quux)) and so foo's argument is the the list whose first element is the symbol quote and whose second element is the symbol quux. A list is of type cons. I haven't tried it, but (foo quux) should give you symbol. //J |
|
#5
| |||
| |||
| In article <30bcc5c4-371f-456d-ba7f-d6c4ae90602a@j20g2000hsi.googlegroups.com>, "Leslie P. Polzer" <leslie.polzer@gmx.net> wrote: > Sorry if it seems tremendously stupid, but what happens here: > > [41]> (defmacro foo (bar) (format t "~A" (type-of bar))) > FOO > [42]> (foo 'quux) > CONS > NIL > > so that the symbol becomes a cons? Do a MACROEXPAND on (foo 'quux). bar is (quote quux) type-of bar is cons FORMAT t prints "CONS" and returns NIL So the MACROEXPANSION of the above is just NIL. |
|
#6
| |||
| |||
| On Jan 16, 1:25 am, Rainer Joswig <jos...@lisp.de> wrote: > bar is (quote quux) Yeah, (QUOTE quux) is obviously a CONS. Now I see it, too ![]() Thanks! And no, I didn't mean to quote the macro expansion here. |
|
#7
| |||
| |||
| On Jan 15, 5:27*pm, "Leslie P. Polzer" <leslie.pol...@gmx.net> wrote: > Sorry if it seems tremendously stupid, but what happens here: > > [41]> (defmacro foo (bar) (format t "~A" (type-of bar))) > FOO > [42]> (foo 'quux) > CONS > NIL > > so that the symbol becomes a cons? Others have answered the superficial question. The real question is why you want this to be a macro? FORMAT and TYPE- OF are both functions. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.