On 12 May 2014 10:48, gamma235 <[email protected]> wrote:
> When I try this using your code above I get a stack-trace that I can't
> understand. Am I using it wrong?
>
> (transparent-chan c)
>> (transparent-put c 42)
>> (transparent-take c)
>>
>
Yep, try this instead:
(def tc (transparent-chan c))
(transparent-put tc 42)
(transparent-take tc)
I'm creating a new data structure that contains both a channel and an atom,
and I'm returning it from transparent-ch. I'm not modifying the original
channel in any fashion.
The destructuring is just a shortcut. This code:
(defn transparent-put [{:keys [channel buffer]} x]
(go
(>! channel x)
(swap! buffer conj x)))
Is equivalent to:
(defn transparent-put [tc x]
(let [{:keys [channel buffer]} tc]
(go
(>! channel x)
(swap! buffer conj x)))
Which is equivalent to:
(defn transparent-put [tc x]
(let [channel (:channel tc)
buffer (:buffer tc)]
(go
(>! channel x)
(swap! buffer conj x)))
- James
--
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.