On Mar 2, 2009, at 2:52 AM, Zededarian wrote:
>
> Ah, I see. Out of curiosity, is there some design reason why clojure
> doesn't reduce my original function to the apply version? I mean,
> take the function:
> (loop [x '(1 2 3) fin '()]
> (if x
>(recur (cdr x) (concat fin (list x)))
>
Ah, I see. Out of curiosity, is there some design reason why clojure
doesn't reduce my original function to the apply version? I mean,
take the function:
(loop [x '(1 2 3) fin '()]
(if x
(recur (cdr x) (concat fin (list x)))
fin))
Will, at least if I'm interpreting your responses corre
No, it will be O(n), where the "cool magic" is in the use of lazy
sequences.
Here's a very simple way to write an O(n) lazy concat:
user> (defn my-concat [& seqs]
(when-first [s seqs]
(if (seq s)
(lazy-seq (cons (first s) (apply my-concat (rest s) (rest
seqs))
Thanks!
One follow up question, though: will the first solution take O(n^2)
time, or is clojure clever enough to keep track of where the end of a
sequence is on its own (or, alternately, to start by concatenating the
last two elements and working backward)? Or does it do some other
cool magic to
Hi,
The problem is that you end up with the front of your worklist being
wrapped in nested calls to lazy-seq, one per each call to
concat. Then, realizing the first element causes a stack overflow.
This wouldn't happen if you reversed the arguments to concat, but then
you wouldn't get what you
My ultimate goal is to get a list of all the words in a file in
order. I have a function that will get a list of all the words on one
line of this file in order, and I want to efficiently concatenate
these lists to end up with one large list. I'm working with about
12000 lines right now, but in