From: Caelan Burris on 9 Aug 2010 10:34 Given the following definitions: (defmacro foo (x) (x 1 2 3)) (defmacro bar (x) `(,x 1 2 3)) Why does (foo if) produce an error, while (bar if) doesn't?
From: Tamas K Papp on 9 Aug 2010 10:42 On Mon, 09 Aug 2010 07:34:20 -0700, Caelan Burris wrote: > Given the following definitions: > > (defmacro foo (x) > (x 1 2 3)) > (defmacro bar (x) > `(,x 1 2 3)) > > Why does (foo if) produce an error, while (bar if) doesn't? For the same reason that the expression IF produces an error. Did you read the error message? Tamas
From: Zach Beane on 9 Aug 2010 10:42 Caelan Burris <caelanburris(a)gmail.com> writes: > Given the following definitions: > > (defmacro foo (x) > (x 1 2 3)) > (defmacro bar (x) > `(,x 1 2 3)) > > Why does (foo if) produce an error, while (bar if) doesn't? If you had a function named X available at macroexpansion time, and it returned suitable code, FOO wouldn't produce an error. One way to think about backquotes is as code templates. They're useful for providing an easily visible structure into which values can be interpolated with a concise syntax. Zach
From: Zach Beane on 9 Aug 2010 10:49 Tamas K Papp <tkpapp(a)gmail.com> writes: > On Mon, 09 Aug 2010 07:34:20 -0700, Caelan Burris wrote: > >> Given the following definitions: >> >> (defmacro foo (x) >> (x 1 2 3)) >> (defmacro bar (x) >> `(,x 1 2 3)) >> >> Why does (foo if) produce an error, while (bar if) doesn't? > > For the same reason that the expression IF produces an error. > Did you read the error message? "The function X is undefined."? Zach
From: Pascal J. Bourguignon on 9 Aug 2010 13:32
Caelan Burris <caelanburris(a)gmail.com> writes: > Given the following definitions: > > (defmacro foo (x) > (x 1 2 3)) > (defmacro bar (x) > `(,x 1 2 3)) > > Why does (foo if) produce an error, while (bar if) doesn't? There is nothing in common between these two macros. The first calls a function named X with three arguments. The later builds a list of four elements. If the function X is not defined, or doesn't take three arguments, or doesn't return a valid form, then the same error would occur for (foo whatever) because the parameter X of the macro FOO is not used. Common Lisp is a lisp-2. Values and functions lie in separate name space. -- __Pascal Bourguignon__ http://www.informatimago.com/ |