[ASYNC-6] alts! assumes nth works on ports argument Created: 15/Jul/13 Updated: 14/Oct/15 Resolved: 27/Sep/13
|Reporter:||Brandon Bloom||Assignee:||Timothy Baldridge|
The docstring for alts! reads:
ports is a set of channel endpoints, which
However, trying to use an actual set yields the following exception:
java.lang.UnsupportedOperationException: nth not supported on this type: PersistentHashSet
|Comment by Brandon Bloom [ 07/Aug/13 2:32 PM ]|
Discussed at length in IRC on Aug 7th: http://www.raynes.me/logs/irc.freenode.net/clojure/2013-08-07.txt
|Comment by Rich Hickey [ 07/Aug/13 9:28 PM ]|
The documentation should be changed. alts requires an efficiently nth-able collection (e.g. a vector), else it will be slow.
If CLJS supports nth on sets it is broken.
|Comment by Brandon Bloom [ 07/Aug/13 9:52 PM ]|
> alts requires an efficiently nth-able collection
Is that the case? Or does alts actually only require efficiently sampling a single element from a collection?
Efficient nth is a reasonable proxy, since the only choice we have for randomness is rand-int. However, one could imagine a CollSample protocol that would allow efficient random choice leveraging data-structure-specific knowledge, much as CollReduce works. Given the world as it exists now, I agree that this is a doc bug.
> If CLJS supports nth on sets it is broken.
That's the conclusion we came to in IRC. David quickly fixed this:
|Comment by Timothy Baldridge [ 27/Sep/13 8:47 AM ]|
fixed in master
|Comment by Daniel Compton [ 14/Oct/15 5:30 PM ]|
For those reading this in the future, this was fixed by changing the docstring to use vector instead of set. https://github.com/clojure/core.async/commit/ca633479f51481f4aee40b4d60120484839d20c6