That's easy and one of the most common macro questions.
(add-test g)
Now on macro expansion, the macro ADD-TEST is called with the parameter VAR getting the value G, a symbol.
Then you try a list operation. The backquote expression `(+ ,@var) . The value of VAR is G, and you try to splice that into the list (+ ... ). Now the returned expression is (+ . G).
CL-USER 12 > (macroexpand '(add-test g))
(+ . G)
T
(+ . G) is not a valid Lisp form.
Remember, the parameters to a Macro are the unevaluated source expressions.
Compare that with the following:
CL-USER 13 > (macroexpand '(add-test (1 2 3 4)))
(+ 1 2 3 4)
T
You said: 'Can you please explain, why is it not working when variable is passed in to the function?'
Remember, ADD-TEST is NOT a function, it is a macro. A macro gets the source code passed and returns a new form - that form is then later evaluated.
Rainer Joswig
2010-09-20 21:00:21