In Clojure (core.async) what's the difference

2019-02-16 07:11发布

I can't figure out the difference between:

alts!

and

alt!

in Clojure's core.async.

1条回答
对你真心纯属浪费
2楼-- · 2019-02-16 07:50

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.

查看更多
登录 后发表回答