1

I have a clojure macro:

(defmacro show
  [x] `(show-fn ~x)
)

: which given :

(show hello)

I want to resolve to :

(show-fn 'hello)

: How can I do this?

1 Answer 1

3
user=> (defmacro show [x] `(~'show-fn '~x))
#'user/show
user=> (macroexpand '(show hello))
(show-fn (quote hello))

This is called 'symbol capture'. It keeps the symbol from being resolved in the current namespace, as with your example.

Sign up to request clarification or add additional context in comments.

3 Comments

@Zubair Done. Note that it isn't going to actually expand to 'hello, because ' expands to quote. It's the same thing though.
You probably don't want to capture show-fn - it's usually better to let that one be syntax-quoted, like (show-fn '~x).
He did for some reason. Not sure if you were responding to him or me. I was just answering the question rather than giving a lecture on why not to do it.

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.