Hi,

as you might know, the original version actually does run in fixed
stack space, thanks to lazy sequences.

(defn skl
  [tree]
  (map skl (filter seq? tree)))

loop .. recur is the moral equivalent of a while(true) loop in
imperative style. i.e. a slightly disguised (and somewhat more
structured) goto
Only use that as a lowlevel implementation detail.

You can express mostly anything with the sequence library of clojure

Consider

(defn find-in-tree
  ([tree pred?]
    (concat
      (filter pred? tree)
      (mapcat find-in-tree (filter sequential? tree) (repeat pred?)))))

which of course is much simpler written as

(defn find-in-tree
  ([tree pred?] (filter pred? (flatten tree))))

all of which are lazy, hence consume constant stack space

kind regards
-- 
__________________________________________________________________
Herwig Hochleitner

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