Given two (unordered) identical sets, is (first <set>)
guaranteed to always return the same element?
If this is documented somewhere, where is it?
Why I care
The main reason I want this right at the moment is for searching graphs that are produced by random processes, yielding results to which more random processes are applied. uber/nodes
and loom/nodes
appear to return sets.
Some of the specifics of the traversal order don't matter, but some do. What matters is that each time I run the program with the same random-number seed, I should get the same results.
I'd prefer not to impose an ordering on the nodes or edges of the graph. That seems to impose computational overhead for no real benefit—except determinism.
I've run into this same need on other projects, not involving graphs. Often with genetic algorithms, I've got lots of sets that I chug through (but no duplicates!). The sequence in which the program goes through the set doesn't matter except that it affects how many times the random-number generator is called before a given element is processed. So, more generally, you could say that my question is about whether (seq <set>)
is deterministic.
Redefining the problem?
If the answer is no, or if it's yes but a sin against Clojure, here's another way to state the problem: What's the Clojurely way to work through a collection item-by-item, where you never want duplicates and where you don't care about the order—except that you need the items to come in the same order each time you run the program? (More precisely, every time you call the function with the same random-number seed.)
That may be hopeless, though, unless I'm up for writing another graph library.