Thanks for posting these examples; I'd never thought of using multimethods that way. And thanks for the Swing example. I'm really interested in functional-reactive programming; hope we see lots of that stuff in Clojure. Anyone ever used FrTime in PLT? Here's the Swing events without the Swing. Didn't know you could override deref and invoke like that....
(import '(java.util.concurrent LinkedBlockingQueue) '(clojure.lang IDeref IFn)) (defn hydra "returns a BlockingQueue, will return a new infinite lazy-seq wrapped in a delay evertime it is deref'ed. all items put in the LinkedBlockingQueue will be added to all the lazy-seqs producded by deref'ing" [] (let [consumers (atom nil) producer (proxy [LinkedBlockingQueue IDeref IFn] [] (invoke [& x] (doseq [y x] (.put this y))) (deref [] (let [x (LinkedBlockingQueue.)] (swap! consumers conj x) (delay (repeatedly #(.take x))))))] (future (while true (let [x (.take producer)] (doseq [y @consumers] (.put y x))))) producer)) (def queue (hydra)) ;see it working (def results (atom nil)) (def show (fn [] (.start (Thread. (fn [] (doseq [i (force @queue)] ;derefing the lbq from hydra returns a delay wrapped lazy-seq (swap! results conj i))))))) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en