On Jan 15, 1:21 pm, Nicolas Buduroi <nbudu...@gmail.com> wrote: > Hi, I'm still not familiar with laziness and I'm trying to make a > function recursively walk arbitrary data structures to perform some > action on all strings. The non-lazy version is quite easy to do: > > (use > 'clojure.walk > 'clojure.contrib.str-utils) > > (defn recursive-string-walk [f form] > (walk #(if (string? %) (f %) (recursive-string-walk f %)) > identity form)) > > - budu
One more thought (sorry, I'm having too much fun with this problem).... I notice that since walk does not traverse anything except collective data types, your recursive-string-walk will not call the function f on just a string argument: user=> (recursive-string-walk reverse "hello") "hello" This, of course, may be exactly the behavior that you desire, but a version which handles strings might be useful for a "string walking" function: (defn rsw [f form] (if (string? form) (f form) (walk (partial rsw f) identity form) ) ) Unfortunately, this is also non-lazy and will probably still blow your stack. :) -tom
-- 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