On Jun 14, 5:31 am, Max Suica <max.su...@gmail.com> wrote:
> > A lazy right fold[1] allows short-circuiting, so here's one attempt:
>
> Wow, that made my head explode.
>
> Some points:
>
> 1) That's not exatly foldr, as  (foldr + 0 [range 100]) ought to work

Agreed, having to write that as

(foldr (fn [x f-rest] (+ x (f-rest))) 0 (range 100))

shows that deficiency rather quickly.

> 2) Foldr is not tail recursive nor can you really call an anamorphism
> lazy

The function I posted wasn't tail recursive either.  It called the
passed in f on the (delayed) result of the recursion before
returning.  It's certainly lazy on the spine of the list, in that
evaluation is deferred until the caller needs a value, just like foldr
should be.

It's the inability to delay evaluation of arbitrary args (the
recursion, here) that keeps us from being able to write, say, (foldr +
0 [1..10]) and have it work.

> 3) Never the less you did it, through some mind twisting continuation
> passing style
> 4) That's fn awesome :D where did you learn it?

There're three ways to defer evaluation that I know of in Clojure:
delayed macro evaluation, force/delay, and what you see.  The macro
approach doesn't really work, the force/delay looks even worse, so ...

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