在Clojure(core.async)中alts和alt之间有什么区别?

在Clojure(core.async)中alts和alt之间有什么区别?

问题描述:

我无法弄清楚之间的区别:

I can't figure out the difference between:

alts!

alt!



core.async 。

alts!一个函数,接受要从中取出的频道向量和/或带有值的频道(以双向向量的形式: [cv] )。可以动态地构造向量;调用 alts!的代码可能不知道它将选择多少个频道(并且实际上该调用不需要在调用中保持不变)。

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!是一个方便的,基本上作为 cond 和 alts!。这里,端口(通道或通道+值对)的数量必须静态地知道,但是在实践中这是经常的情况,并且 cond 清除

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!使用 alts! c $ c>;除了语法方便之外,它不提供额外的功能。

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