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?

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.