开发者

Does all clojure code work within a java proxy?

开发者 https://www.devze.com 2023-01-30 04:19 出处:网络
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:

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 开发者_如何学Pythonfunctions within the proxy?


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"
0

精彩评论

暂无评论...
验证码 换一张
取 消