Hi there,

I have a program that produces multidimensional LazySeqs, i.e. seqs of seqs
of seqs of...

I would like to write a function to convert these multidimensional LazySeqs
to vectors. This is in case a user needs constant lookup time.

The following function will do it:

(defn vectorize [obj]
  (if-not (seq? obj)
    obj
    (vec (map vectorize obj))))

(def foo (list 1 2 3 (list 1 2 4 (list 1 4)) 2))

(vectorize foo)
>> [1 2 3 [1 2 4 [1 4]] 2]

However, since there is no recur there, the function is liable to blow the
stack on a very deep data structure (or so I gather from reading about
Clojure's lack of TCO).

I cannot figure out how to write the function using recur. Any ideas?

More broadly, this would not be necessary if I could tell my LazySeqs to
cache accesses and they cached them using a constant-lookup-time data
structure. I've seen mention that LazySeqs cache access, but they don't seem
to for me:

user=> (def foo (lazy-seq (range 10000000)))
user=> (time (nth foo 9999999))
"Elapsed time: 655.924286 msecs"
9999999
user=> (time (nth foo 9999999))
"Elapsed time: 675.42013 msecs"
9999999

Maybe I'm misunderstanding what is meant by caching.

Any thoughts on the vectorize function or caching?
Thanks.

Garth

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