From: Scott Alexander
Subject: Possibly inefficient macro bind a list of symbols to function defs
Date:
Message-ID: <CMKw7r.JFx@world.std.com>
RE: My previous post
Trying to write a macro which takes a list of symbols
and binds each symbol to a function definition using 'defun'
The following code seems to do what I want:
(defmacro defsums (symbol-list)
(dolist (s symbol-list)
(eval `(defun ,s (x y) (+ x y)))))
After evaluating the above, evaluation of a form like
(defsums (add-up total sigma))
defines three new functions, so
(add-up 2 3)
returns '5'.
Is the use of 'eval' in the above macro definition terribly
inelegant or inefficient, or is it the only way to go?
I was under the impression that a macro call, once fully expanded,
still gets evaluated once as well, and I have heard that calls
to 'eval' are inefficient and usually avoidable, so I suspect
there may be a better way of coding the above macro 'defsums'.
Thanks for any help!
Scott Alexander
········@world.std.com
The San Juan Star (newspaper)
San Juan, Puerto Rico