Perhaps this is well known to others, but on the chance that maybe it isn't I 
thought I'd share.

In clojure.walk both prewalk and postwalk use recursion in ways that will blow 
the stack for sufficiently deep nested structures. We had been using them 
happily until recently when things got too big, and then we had problems. 

For our application I was able to replace my previous walking with a call to 
prewalkseq as defined below (which is only for seqs and uses zippers to avoid 
the recursion -- and note that I'm using MichaƂ Marczyk's recently patched 
version of seq-zip so that it doesn't do the wrong thing with embedded 
instances of ().)

(defn prewalkseq
  "Like prewalk but only for seqs and uses zippers."
  [f s]
  (loop [z (seq-zip s)]
    (if (zip/end? z)
      (zip/root z)
      (recur (zip/next (zip/replace z (f (zip/node z)))))))) 

That's all I need at the moment, but it's not immediately obvious to me how 
this would be done for postwalk, and it would be nice if all of clojure.walk 
could be made safe for large structures.

 -Lee

-- 
-- 
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/groups/opt_out.

Reply via email to