Re: A better flatten

2009-09-02 Thread Meikel Brandmeyer
On Sep 3, 1:13 am, Sudish Joseph wrote: > (defn flatten-2 [lst] >   (lazy-seq >     (if-let [x (first lst)] >       (let [xs (rest lst)] >         (if (seq? x) >           (concat (flatten-2 x) (flatten-2 xs)) >           (cons x (flatten-2 xs))) This version is broken: user=> (flatten-2

Re: A better flatten

2009-09-02 Thread Krukow
On Sep 3, 1:13 am, Sudish Joseph wrote: > The other solutions seem higher level, but it's worth noting that > destructuring -- (let [[x & xs] lst] ...) -- uses next and is therefore > not fully lazy in that you will peek ahead by one into the lazy > sequence, so to speak.  You have to use explic

Re: A better flatten

2009-09-02 Thread Sudish Joseph
Hi Karl, The other solutions seem higher level, but it's worth noting that destructuring -- (let [[x & xs] lst] ...) -- uses next and is therefore not fully lazy in that you will peek ahead by one into the lazy sequence, so to speak. You have to use explicit first / rest to get that: ;; with de

A better flatten

2009-09-02 Thread Krukow
Hello, At some point I needed at "flatten" function taking a list of atomic elements or nested lists, and producting a "flat" list of only atomic elements (in the same order). It should be lazy. This is what I came up with. Can anyone see a more elegant solution (I feel I am working "low-level" s

Re: A better flatten

2009-09-02 Thread Sean Devlin
It's in c.c.seq-utils You can look up stuff here: http://richhickey.github.com/clojure-contrib/api-index.html On Sep 2, 4:12 pm, tmountain wrote: > I believe the flatten in contrib is defined as follows. I can't > remember which module I found it in. > > (defn flatten >   "Takes any nested com

Re: A better flatten

2009-09-02 Thread tmountain
I believe the flatten in contrib is defined as follows. I can't remember which module I found it in. (defn flatten "Takes any nested combination of sequential things (lists, vectors, etc.) and returns their contents as a single, flat sequence. (flatten nil) returns nil." [x] (filter (co