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

◇◆丶佛笑我妖孽 提交于 2019-11-30 21:40:14

问题


I can't figure out the difference between:

alts!

and

alt!

in Clojure's core.async.


回答1:


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.



来源:https://stackoverflow.com/questions/22085497/in-clojure-core-async-whats-the-difference-between-alts-and-alt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!