Hello,
I wrote a macro that generates HTML code. I then defined another macro
built on top of this macro to create a HTML template.
I want to be able to pass this HTML template(macro) to a function
which computes some stuff and insert the result by a call to the
template.
I read in google groups somewhere that (eval (funcall (macro-function
'my-macro) (cons 'my-macro list))) might be the solution. Is there any
problems with this solution as I the use of eval is discouraged.
My second question is when is the use of eval appropriate or
inappropriate?
Thanks.
In article <····························@posting.google.com>,
Delaregue <·········@netscape.net> wrote:
>Hello,
>
>I wrote a macro that generates HTML code. I then defined another macro
>built on top of this macro to create a HTML template.
>
>I want to be able to pass this HTML template(macro) to a function
>which computes some stuff and insert the result by a call to the
>template.
>
>I read in google groups somewhere that (eval (funcall (macro-function
>'my-macro) (cons 'my-macro list))) might be the solution. Is there any
>problems with this solution as I the use of eval is discouraged.
The simpler way to do that is (eval `(my-macro ,@list)).
The way to avoid using eval is to provide a functional version of your
code. You can then provide a macro that expands into a call to the
function:
(defun html-function (list) ...)
(defun html-macro (&rest stuff)
`(html-function ',stuff))
Use html-function when you want to compute the arguments at run time,
html-macro when they're compile-time literals.
>My second question is when is the use of eval appropriate or
>inappropriate?
It's generally only appropriate when there's no alternative.
--
Barry Margolin, ··············@level3.com
Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.