On Wed, Dec 1, 2010 at 10:25 PM, Chris Maier
<christopher.ma...@gmail.com> wrote:
> That sounds like 'reductions':
>
> (reductions + [1 2 4 8])
> ==> (1 3 7 15)

On top of that, both the OP's algorithms are quadratic.

(defn scanl2 [f seed coll]
  (loop [ttl seed [fst & rst] coll acc []]
    (let [ttl (f ttl fst)
          acc (conj acc ttl)]
       (if rst
         (recur ttl rst acc)
         acc))))

is not, but it's not lazy. The above loop can be transformed
relatively trivially into a lazy-seq use that would be lazy;
reductions may be implemented similarly to such a lazy-seq use.

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