Hi,

Am Mittwoch, 13. Juli 2011 11:02:40 UTC+2 schrieb bsmith.occs:
>
> On Wed, Jul 13, 2011 at 08:43, Meikel Brandmeyer <m...@kotka.de> wrote:
> > Hi,
> >
> > I think the culprit is here:
> > 
> https://github.com/clojure/clojure/blob/5f9d6a02c530a02251197e1b844af37440a6b569/src/clj/clojure/core/protocols.clj#L64
> >
> > The line "(recur cls (next s) f (f val (first s)))" must be written as
> >
> > (let [v (f val (first s))]
> >   (recur cls (next s) f v))
> >
> > for your scenario to work.
>
> I'm probably being a little dense this morning, but...
>
> I've stared at both examples for some time now and still don't see why
> the first should behave differently than the second.
>
> Can you give me a hint?
>
Because - although not guaranteed - clojure evaluates function arguments 
from the left to the right. So the next element in the sequence is realised 
before the function f is called. In the second snippet f will be called 
always before the next element is realised. If f is pure, there won't be a 
difference. If f is not pure, it will be a difference. Especially if next 
relies on side-effects of f (or vice versa) as in the scenario described by 
the OP.

Sincerely
Meikel

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