Hey guys, I took your suggestions and just wanna deliver the finished 
product. I included the macro in there for practice, but agree it is 
probably not necessary. Thanks for all your help. 

p is for pretty :)
 

> (defn pchan [ch]
>   {:channel ch, :buffer (atom [])})
>
 

> (defn pbuff [{:keys [ch buffer]}]
>    (println @buffer))
>
 

> (defn pput [{:keys [channel buffer]} v]
>   (do 
>     (go 
>      (>! channel v))
>     (swap! buffer conj v)
>     (println "put " v)))
>
 

> (defn ptake [{:keys [channel buffer]}]
>     (go 
>      (let [v (<! channel)]
>        (if-not (empty? @buffer)
>         (do 
>        (swap! buffer pop)
>        (println "took " v)))))
>     (println "take pending ..."))
>
 

> (defmacro def-pchan
>   ([name]
>    `(def ~name (pchan (chan))))
>   ([name buff]
>    `(def ~name (pchan (chan ~buff)))))
>
 

> (defn clear-buffer [{:keys [buffer]}]
>   (reset! buffer []))
>
> it works!  

> (def-pchan pc)
> (:buffer pc)
> (pbuff pc)
> (ptake pc)
> (pput pc 42)
> (clear-buffer pc)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to