This doesn't work because defparameter is a macro that doesn't evaluate
the second term of the input list to obtain the symbol name:
(defmacro grab-defun-name (list)
`(defparameter (second ,list) ,list))
I want to obtain the second value of the variable list which requires an
unquote on the list and an unquote on (second ,list)--which leads to too
many commas for one backquote.
I just want to understand whether achieving this is possible without
resorting to reimplementing defparameter or using EVAL. I believe I have
struck this situation in the FAQ:
http://www.faqs.org/faqs/lisp-faq/part3/
On the other hand, EVAL can sometimes be necessary when the only
portable interface to an operation is a macro.
I need to capture each function and store its list representation
(conveniently with the same name) along with evaluating the function
because I am simultaneous using the function and parsing its elements to
produce presentation markup.
Thanks,
Adam
> Hi all,
>
> This doesn't work because defparameter is a macro that doesn't evaluate
> the second term of the input list to obtain the symbol name:
>
> (defmacro grab-defun-name (list)
> `(defparameter (second ,list) ,list))
>
> I want to obtain the second value of the variable list which requires an
> unquote on the list and an unquote on (second ,list)--which leads to too
> many commas for one backquote.
Don't you just want
(defmacro grab-defun-name (list)
`(defparameter ,(second list) ,list))
>
> I just want to understand whether achieving this is possible without
> resorting to reimplementing defparameter or using EVAL. I believe I have
> struck this situation in the FAQ:
>
> http://www.faqs.org/faqs/lisp-faq/part3/
>
> On the other hand, EVAL can sometimes be necessary when the only
> portable interface to an operation is a macro.
>
I don't think this is one of those times.
Tim
howseabout `(defparameter ,(second list) ,list)? Then your problem may be
... well, I'll shut up. But I am surprised the defparam value ",list" is not
quoted: "',list". But I am only guessing at your intent. OK, I'll shut up.
kenny
clinisys
> Don't you just want
> (defmacro grab-defun-name (list)
> `(defparameter ,(second list) ,list))
Almost! Before the example I posted I was continually doing the same thing:
[1]> (defmacro grab-defun-name (list)
`(defparameter ,(second list) ,list))
grab-defun-name
[2]> (grab-defun-name '(defun test () 123))
*** - defparameter: non-symbol (defun test nil 123) cannot be a variable
Now I realise I was actually finding the second list value of
(quote (defun test nil 123))!
But now that I am no longer quoting the input value I need to add a quote
to the last list item:
(defmacro grab-defun-name (list)
`(defparameter ,(second list) ',list))
Now without quoting the input:
(grab-defun-name (defun test () 123)
The function is simultaneous captured and evaluted!
[7]> test
(defun test nil 123)
[8]> (test)
123
Regards,
Adam
You wouldn't be surprised if you tried to get it to work using this input:
(grab-defun-name '(defun test () 123))
I had originally intended to create the global variable and then evaluate
the list. Impressively it all works by the macro capturing the defun list
before it evaluates.
Thanks,
Adam
The defun won't be evaluated if you quote the list. Depending on how it will be
used, I would probably do it differently:
(defmacro defun-grab (name lambda-list &body body)
(let ((defun-form `(defun ,name ,lambda-list ,@body)))
`(progn
(defparameter ,name ',defun-form)
,defun-form)))
(defun-grab test2 () 123)
--
Martin Simmons, Xanalys Software Tools
zne...@xanalys.com
rot13 to reply
> The defun won't be evaluated if you quote the list. Depending on how
> it will be used, I would probably do it differently:
>
> (defmacro defun-grab (name lambda-list &body body)
> (let ((defun-form `(defun ,name ,lambda-list ,@body)))
> `(progn
> (defparameter ,name ',defun-form)
> ,defun-form)))
>
> (defun-grab test2 () 123)
This is much preferred thanks Martin. And it's not just because it will be
evaluated even if I quote the list: it's also a hassle closing the bracket
on the separate defun-grab.
Regards,
Adam