Yoshinori Kohyama <yykohy...@gmail.com> writes:

Hi!

> Here is my fold-right.
>
> (defn fold-right [f s coll]
>   ((reduce (fn [acc x] #(acc (f x %))) identity coll) s))

Very elegant, but sadly it blows the stack on larger collections.  On my
system, the threshold is somewhere beetween 15.000 and 16.000 elements.

Something much less elegant (and slower in cases where your variant also
does the trick) is:

    (defn fold-right [f s coll]
      (reduce #(f %2 %1) s (reverse coll)))

Bye,
Tassilo

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