On Dec 23, 2008, at 5:19 PM, MattyDub wrote:
On the Java Interop page (http://clojure.org/java_interop), the proxy macro is described as creating "...a instance of a proxy class that implements the named class/interface(s)...". Is this done using Java Dynamic Proxy Classes (http://java.sun.com/j2se/1.5.0/docs/guide/ reflection/proxy.html)?
That seems likely but I don't know for sure. The implementation is in the Clojure distribution in src/clj/clojure/core_proxy.clj and supporting classes in src/jvm/clojure/lang.
Background to this question: I came across a blog post (http:// www.plt1.com/1070/even-smaller-snake/) which claims to implement the game "Snake" in 35 lines of clojure. However, it doesn't run; for one thing, in line 26, the syntax for doseq is wrong. Another problem has to do with calling methods from the JPanel class on the proxied JPanel object created in the run-snake function. It looks like you shouldn't call methods on proxied classes that aren't the ones you supplied when creating the proxy - is that true?
It's not true. In addition to the update to doseq's syntax, the code there also needs an update to the new "doto" syntax. Now, when calling methods on a Java object instance inside a "doto" form, the method names need to be prefixed with ".":
(doto panel (.setFocusable true) (.addKeyListener panel))(doto (new JFrame "Snake") (.add panel) (.setSize 800 600) (.setVisible true))
The code in the blog post worked for me with today's Clojure after I made those two updates.
--Steve
smime.p7s
Description: S/MIME cryptographic signature