On Dec 5, 2:10 pm, Alex Ott <alex...@gmail.com> wrote:
> Re
>
> jweiss  at "Sun, 5 Dec 2010 10:29:41 -0800 (PST)" wrote:
>  j> I'm no expert on this, but i'll take a crack at it.
>
>  j> I think it's because sets don't (necessarily) impose any order, so
>  j> there's no concept of "first" or "nth".  So destructuring would
>  j> essentially be assigning a random item to x, or for join, joining them
>  j> in random order.
>
> Sometimes, order doesn't matter, for example, I want to print data from set
> (or any collection that is transformable into sequence), using some
> separator between elements...
>
> For some operations we can't also predict order, for example, conj behaves
> differently for lists and vectors
>
> --
> With best wishes, Alex Ott, MBAhttp://alexott.blogspot.com/       
> http://alexott.net/http://alexott-ru.blogspot.com/
> Skype: alex.ott

If you wanted to, for example, print a set with separators in between,
would you need to use destructuring?

I'd just do (apply str (interpose "," #{:a :b :c})
-> ":a,:b,:c"

I don't think conj adding to the front for lists and the end for
vectors is unpredictable at all.  I know that

(conj '(1 2) 3))
-> (3 1 2)

and

(conj [1 2] 3)
-> [1 2 3]

before I even type it on a REPL.  That's totally different than nth
for a set being undefined.  It's undefined on purpose.

Now, if you are using a sorted-set, then you have a point there, I
would expect that nth means something then.  But yeah, clojure doesn't
let you call nth on it directly, you have to make a seq out of it
first.  Not sure what the performance implication is there, but it's
not much effort to write:

(nth (sequ­ence (sort­ed-set 1 3 2)) 2)
-> 3

I will let people who are more knowledgeable comment on why there's no
nth on a sorted-set.

-- 
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

Reply via email to