0
(defmacro foo (x)
    `(defun ,xt ()
         (format t "hullo")))

(foo bar)

will not define a function bart, since ,xt is read as the variable xt rather than the variable x plus a t. But is there a way to get a function bart by supplying the argument bar?

Toothrot
  • 334
  • 2
  • 10

1 Answers1

3

You need to create the function name (which is a string then) and then convert it to a symbol, for example:

(defmacro foo (x)
  `(defun ,(intern (format nil "~aT" x)) ()
     (format t "hullo")))

then

? (foo bar)
BART
? (bart)
hullo
NIL
uselpa
  • 18,732
  • 2
  • 34
  • 52