two element vectors implement MapEntry, two element lists do not
On Sat, Jul 11, 2009 at 9:09 AM, Stuart
Halloway wrote:
>
> Is there a reason these work differently?
>
> (into {} [(list 1 2) (list 3 4)])
> -> java.lang.ClassCastException: java.lang.Integer cannot be cast to
> java.util.Map$Entry
Is there a reason these work differently?
(into {} [(list 1 2) (list 3 4)])
-> java.lang.ClassCastException: java.lang.Integer cannot be cast to
java.util.Map$Entry (NO_SOURCE_FILE:0)
(into {} [(vector 1 2) (vector 3 4)])
-> {3 4, 1 2}
Cheers,
Stu
--~--~-~--~~~---
On Fri, May 15, 2009 at 2:36 PM, Vagif Verdi wrote:
>
> What are the use case scenarios where one is preferable to the other
> in clojure ?
A lot of good points have been raised in this thread. A minor point to
add is that literal vectors are a bit easier to pick out in code than
literal lists.
On May 16, 2009, at 8:23 PM, Michel S. wrote:
That's a bit of a red herring, though? You can always rewrite the code
to use normal (as opposed to tail) recursion, if you don't want to use
reverse. Depending on how large the resulting list is, it's a space-
vs-
time tradeoff: the normal recurs
On May 15, 4:41 pm, "Stephen C. Gilardi" wrote:
>
> Another nice benefit of Clojure's efficient vectors over lists is that
> functions that produce a collection of results can produce and store
> them in order without needing to "reverse" the result just before
> returning. Reversing is a
In my own experimentation, I was really surprised to find that
traversal over vectors seemed to be faster than lists, so I tend to
use vectors rather than lists for any "fixed collection" that I'm
basically just traversing once I've built. Haven't benchmarked
recently, though, so this could have
Remember clojure, like other lisps, is homoiconic: the program code
itself is clojure data. Lists are very common in clojure, since a list
is is used in the function invocation syntax, e.g. (inc 0).
Otherwise, used as a general purpose lists have the same benefits of
linked lists over arrays that
On May 15, 2009, at 3:36 PM, Vagif Verdi wrote:
It looks to me like vectors almost completely overtake lists for all
purposes.
I think that's a fair statement.
Lists are still:
- key as the data structure that represents a "call" (to a function,
macro, or special form)
- useful for c
And here are some numbers from my machine:
(def my-list (list 'a 'b 'c 'd 'e 'f 'g 'h 'i 'j))
(def my-vector ['a 'b 'c 'd 'e 'f 'g 'h 'i 'j])
; ~44ms
(time (dotimes [x 100]
(conj my-list 'k)))
; ~26ms
(time (dotimes [x 100]
(pop my-list)))
; ~100ms
(time (dotimes [x 100]
(conj my-vec
I'm no expert, but I think this explain some:
Clojure's conj function is like Lisp's cons, but "does the right
thing", depending on the data type. It is fast to add something to
the front of the list, and slower to add something to the end.
Vectors are the opposite, you can add to the end fast,
What are the use case scenarios where one is preferable to the other
in clojure ?
It looks to me like vectors almost completely overtake lists for all
purposes.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Clojur
11 matches
Mail list logo