To avoid the doall-concat, you'd just have the base case return [] (btw,
you don't need the apostrophe for vectors or for the empty list), and use
`into` rather than `concat`.

If you're looking for something that exploits the structure of flatten and
uses an accumulator, you could do this:

(defn my-flatten
  [xs]
  (letfn [(my-flatten-aps [xs avec]
            (if (empty? xs)
              avec
              (let [x (first xs), ys (rest xs)]
                (if (sequential? x)
                  (if (seq x)
                    (recur (cons (first x) (cons (rest x) ys)) avec)
                    (recur ys avec))
                  (recur ys (conj avec x))))))]
    (my-flatten-aps xs [])))

The idea is that if you have a non-empty sequence in the first position,
you pull out its first element and stick it on the front of the overall
sequence.

So ((1 2 3) 4 5) will recur as (1 (2 3) 4 5).
The next go around will pick up that 1 is atomic and add it to the
accumulator, and so on.

If you have an empty sequence in the first position, you just skip over it
entirely.

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to