Skip to content

Instantly share code, notes, and snippets.

@catharinejm
Created April 29, 2011 23:13
Show Gist options
  • Save catharinejm/949200 to your computer and use it in GitHub Desktop.
Save catharinejm/949200 to your computer and use it in GitHub Desktop.
Somthing crazy
;; 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