I wouldn't expect it to work in a `for` comprehension, because that's
combining laziness (which uses function thunks under the hood) with the
async state machines. In general, you shouldn't do side-effects in a
`for`, though I'd be surprised if you couldn't take at the input.
This works
(let [ch (clojure.core.async/to-chan (range 10))
ch2 (clojure.core.async/chan 2 (partition-all 2))]
(clojure.core.async/pipe ch ch2)
(clojure.core.async/<!!
(clojure.core.async/go (for [x (clojure.core.async/<! ch2)]
x))))
Returning (0 1), but that's probably not what you'd want.
On Fri, Aug 26, 2016 at 8:02 AM hiskennyness <[email protected]> wrote:
> Doesn't work in a FOR loop either. Thank god for LOOP! :)
>
> -kt
>
>
> On Thursday, August 25, 2016 at 7:21:20 PM UTC-4, hiskennyness wrote:
>>
>> I am getting an error about >! not being in a go block with this code:
>>
>> (go-loop [state :nl
>> column 0
>> last-ws nil
>> buff ""]
>> (let [line-out (fn [c b]
>> (>! out (apply str b (repeat (- col-width (count
>> b)) \space))))]
>> (cond
>> (>= column col-width)
>> (condp = state
>> :ws (do
>> (line-out \| buff)
>> (recur :nl 0 nil ""))
>> ..etc etc
>>
>> I just changed the line-out call to just do...
>>
>> (>! out-chan buff)
>>
>> ...and it worked fine.
>>
>> So the failing code is both dynamically and lexically within the scope of
>> the go-loop --- is that supposed to be that way? Or am I completely missing
>> something?
>>
>> -kt
>>
>> --
> 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.
>
--
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.