Hi Rich, all, Ever since the new implementation of watchers I've been itching to try out Cells again. It worked great for agents. I ran into a snag, though, when I tried to make cells out of refs. Here's an example.
I make two refs: (def r1 (ref 1)) (def r2 (ref (+ 10 @r1))) Add a watcher so that r2 gets updated whenever r1 changes: (add-watcher r1 :send (agent nil) (fn [a r] (dosync (ref-set r2 (+ 10 @r))))) Seems to work: (println @r1 @r2) ;;=> 1 11 (dosync (ref-set r1 2)) (println @r1 @r2) ;;=> 2 12 Unless I go too fast: (do (dosync (ref-set r1 3)) (println @r1 @r2)) ;;=> 3 12 And I have to wait for the watcher to catch up: (println @r1 @r2) ;;=> 3 13 I guess I was hoping that the watcher on a ref would be called synchronously in the same transaction that modified the ref. I'm not sure if that's possible, or even desirable. I found a way around, but I had to abandon watchers in the process. So I suppose my question is, do watchers have to be agents? -Stuart Sierra --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---