5

I was wondering if there is any clojure code or macros that does not work when embedded within a clojure proxy for java code, eg:

(proxy [Some Java Interface] []
  (some Java Method [args]
  ...
  Clojure code
  ...
  )
)

Or, can I only embed calls to Java functions within the proxy?

1 Answer 1

6

Any Clojure code should work inside proxy.

Behind the scenes, Clojure functions are compiled into Java objects anyways, and calling a Clojure function is technically a Java method call itself. Macro expansion still works normally with proxy. Reader macros all work normally etc.

user> (defmacro foo [] "FOO")
#'user/foo

user> (.toString (proxy [Object] [] 
                   (toString [] 
                     (str (foo) \space (reduce + (range 5))))))
"FOO 10"
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.