Jarkko Oranen <chous...@gmail.com> writes:
> On Jul 15, 1:54 pm, Jan Rychter <j...@rychter.com> wrote:
>> I've been looking for a function that would take a seq and create a list
>> (a real clojure.lang.PersistentList), but haven't found one. The closest
>> I got was:
>>
>> (apply list my-seq)
>>
>> Essentially, I'm looking for something similar to (vec) that returns
>> lists.
>>
>> --J.
>
> Why would you want to do this? Seqs are nearly identical to lists (The
> only difference I can think being that lists are Counted, while seqs
> are not). If it's about forcing strictness, You can use 'doall.

I rely heavily on count being O(1). I have stacks implemented on top of
lists and if those lists turn into seqs, the performance impact is huge.

> However, if you really do need a PersistentList, then (apply list the-
> seq) is what you need. The vec function is a shortcut for (apply
> vector the-seq), provided in the standard library because vectorising
> a seq is rather common.

Based on my (admittedly limited) experiments with a profiler, apply
seems to be a rather heavyweight tool. And vec doesn't seem to be a
shortcut for apply, it seems it creates the structure directly:

(defn vec
  "Creates a new vector containing the contents of coll."
  ([coll]
   (. clojure.lang.LazilyPersistentVector (createOwning (to-array coll)))))

--J.

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