Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does all clojure code work within a java proxy?

Tags:

java

clojure

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?

like image 488
yazz.com Avatar asked Dec 13 '10 22:12

yazz.com


1 Answers

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"
like image 53
Brian Carper Avatar answered Oct 31 '22 09:10

Brian Carper