On Wed, Mar 23, 2016 at 7:05 PM, Matthias Grabmair < matthias.grabm...@gmail.com> wrote:
> > Thanks, this helps! > > Generally, is there any reason why combinations should not work on sets? I > may have tunnel vision here as they are everywhere in the systems I build. > > A lot of the functions produce permutations/combinations/etc. that are lexicographic in terms of the index of the elements. In other words, if you ask for permutations of a three element sequence, you'll always get back permutations in this order: [first-element second-element third-element] [first-element third-element second-element] [second-element first-element third-element] [second-element third-element first-element] [third-element first-element second-element] [third-element second-element first-element] This gives you control: it is up to you to put them in a seq (or vector) in the order you want the elements, and then call the function. For a traditional lexicographic order, you would sort the items before calling the function. It doesn't make sense for the function to try to sort things first, because in Clojure, many things are not comparable, and maybe that's not the order you want anyway. This is why it is not built to accept sets. Sets have no notion of order. If you are happy with just calling seq on the set and accepting that order, great, you can do that, but you may want to do something more specific (like sorting the elements). The reason you may want to sort the elements first is for testing purposes. I believe that calling seq on a set can produce different results depending on the way the set was built, so calling combinations on two equal sets (that happened to be built differently) would produce differently ordered results. If you put things into a seq in a certain order, you're guaranteed to get the same result. Make sense? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.