Reputation: 3381
Doug Hoyte defines in his introduction to Let Over Lambda the symb function as an essential utility to meta-programming with macros:
In clisp:
(defun mkstr (&rest args)
(with-output-to-string (s)
(dolist (a args) (princ a s))))
(defun symb (&rest args)
(values (intern (apply #'mkstr args))))
Why are symbols so important in macro programming?
Upvotes: 0
Views: 106
Reputation: 60062
Symbols name functions and macros, so if your macro defines functions, it will have to construct symbols.
E.g., when you do (defstruct foo a b c)
, you are defining these functions:
MAKE-FOO
FOO-P
COPY-FOO
FOO-A
FOO-B
FOO-C
(SETF FOO-A)
(SETF FOO-B)
(SETF FOO-C)
which requires constructing the 6 symbols above.
PS. You might find the output of (macroexpand-1 (defstruct foo a b c))
instructive.
Upvotes: 4
Reputation:
Symbols are how things are named in Lisp, and macros often want to talk about names.
Imagine you want to write your own version of defstruct
: well a form like
(defstruct pos x y)
is going to need to create names -- symbols -- like pos-x
, make-pos
, pos-p
and so on. So you need ways of talking about symbols: creating symbols from other ones, creating secret symbols which only you know about and which are different than any other symbols and so on.
I kind of disagree that the symb
function he defines is essential, but you do need to be able to manipulate symbols.
Upvotes: 2