Hi,
I have come up this implementation of fold-right in Scala:

def foldRight[B](z: => B)(f: (A, => B) => B): B = // Here, arrow => in 
front of argument means it is arg by name (lazy) and won't be evaluated 
until required
// z - init, f - combining f, and target sequence is 
    this match {
      case Cons(h,t) => f(h(), t().foldRight(z)(f)) // If "f" doesn't 
evaluate second arg, there will be no recursion...
      case _ => z
    }

Now, I know that Clojure doesn't provide facility such is lazy vals (lazy 
args that is)
and there are lazy sequences.

Could someone aid me in porting it to clojure as plain translation like:

(defn fold-right [z f s] ; z - init, f - combining function, s - target sequence
  (let [[h & t] s]
    (if h
      (f h (fold-right z f t))
      z)))

is eager unlike Scala's lazy variant due to fact there are no lazy 
args/vals and argument is evaluated
regardless if function f evaluates really that argument or not.

I know I could use Clojure's reduce and that it is lazy but I'd like to 
figure out how I could achieve this.

-- 
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/d/optout.

Reply via email to