I am getting my feet wet with core.async and am trying to attach atoms to channels that update automatically and print out to the console as you take and put. This is not for anything serious, just a way to get familiar with the behavior and functionality of the library and practice my Clojure skills. Thanks in advaan
Here is my code: (defn log-name [ch] (symbol (str ch '-log))) > > (defmacro transparent-chan [ch] ;; This is probably not correct, but > I wanna do something like this > (do > `(def ~ch (chan)) > `(def (log-name ~ch) (atom [])) > `(println "new transparent channel created!"))) > > (defn- update [log v] > (do > (swap! log conj v) > (println "log test passed: v " has been logged") > (println "channel contents: " @log))) > > (defn transparent-put [ch v] > (let [log (log-name ch)] > (update log v) > (println "put test passed: " v " has been put on the channel") > (println " rechecking log: "@log) > (go > (let [ch ch > v v] > (>! ch v) > (println v " has been successfully put/read from the channel!"))))) > > (defn transparent-take [ch] > (go > (let [v (<! ch) > log-name (symbol (str ch '-log))] > (swap! log-name #(remove #{v} %)) > (println v "has been removed from channel"))) > (println " removal pending")) My main questions are regarding variable scope: 1) I feel like it is a redundant to define bindings multiple times in my go and let exprs for params that are already passed in as arguments. Is there a more idiomatic way to do this? 2) Whenever I try to create a generic process to automatically generate a log-name for each channel and then call update, I get a 'symbol cannot be cast to atom' error. How can I get around this? It seems to happen even if I don't use the log-name function. 3) Is this a useful thing to be doing: is there a way to query and keep track of what's on a channel without using a macro or atoms? -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.