In Clojure (core.async) what's the difference between alts and alt?
Asked Answered
L

1

27

I can't figure out the difference between:

alts!

and

alt!

in Clojure's core.async.

Lcm answered 28/2, 2014 at 3:17 Comment(0)
S
44

alts! is a function that accepts a vector of channels to take from and/or channels with values to be put on them (in the form of doubleton vectors: [c v]). The vector may be dynamically constructed; the code calling alts! may not know how many channels it'll be choosing among (and indeed that number need not be constant across invocations).

alt! is a convenience macro which basically acts as a cross between cond and alts!. Here the number of "ports" (channels or channel+value pairs) must be known statically, but in practice this is quite often the case and the cond-like syntax is very clear.

alt! expands to a somewhat elaborate expression using alts!; apart from the syntactic convenience, it offers no extra functionality.

Scutate answered 28/2, 2014 at 3:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.