I think I've found a change in the behavior of reduce function, passing from 
1.2.1 to 1.3.0.

Given the following:

(defn lazy []
  (lazy-seq
    (print "*")
    (cons :foo (lazy))))

(defn show []
  (reduce
    (fn [r x] (print "!"))
    []
    (take 10 (lazy))))

This is the output of a call to show using clojure 1.2.1:

*!*!*!*!*!*!*!*!*!*!

So, the reducing function is called for the first time, after the lazy 
sequence produced _only_ one value.

This is the output of a call to show using clojure 1.3.0-beta1:

**!*!*!*!*!*!*!*!*!!

As you can see, the reducing function is not called until the lazy sequence 
has produced _two_ values.

Is this change in behavior known and intended? Can someone explain what 
change in clojure code produced it?

Uninteresting detail: I discovered this trying to migrate my Swing 
application from 1.2.1 to 1.3.0. My lazy sequence is a stream of user events 
(clicks, menu selects, etc), my reducing function is an event handler. Each 
time the handler is called, it gets the "state" of the application before 
the event, and returns the "new state" of the application after the event 
was processed. It seemed a nice way to see the user interaction. But this 
behavior change, has broken things. Now I need two user "interactions" to 
get the first one processed.


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