Created
April 29, 2011 23:13
-
-
Save catharinejm/949200 to your computer and use it in GitHub Desktop.
Somthing crazy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; This works | |
(defn ^:dynamic foo [] "foo") | |
(def o (proxy [Object] [] | |
(toString [] (foo)))) | |
(str o) ;=> "foo" | |
(binding [foo (fn [] "inside binding")] (str o)) ;=> "inside binding" | |
;; But this doesn't... | |
(defn ^:dynamic click-fn [ms-event] | |
(println "click")) | |
(doto panel ;; proxy to JPanel | |
(.addMouseListener (proxy [MouseAdapter] [] | |
(mouseClicked [ms-event] | |
(click-fn ms-event))))) | |
(binding [click-fn (fn [ms-event] | |
(let [x (.getX ms-event) | |
y (.getY ms-event)] | |
(println "x: " x "y: " y)))] | |
(loop [] | |
(Thread/sleep 1000/60) ;; draw 60 times per second | |
(.repaint frame) | |
(recur))) | |
;; Clicks in the loop just print "click", from the original #'click-fn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment