On Feb 17, 10:54 am, Michael Gardner <gardne...@gmail.com> wrote:
> On Feb 17, 2012, at 12:32 PM, Bill Smith wrote:
>
> > It might help to know that (= (range) (range)) does not terminate either.
>
> Of course, since a pairwise sequential comparison (what I assume is going on 
> under the hood) will never find a non-matching pair.
>
> > It appears that the = operator wants to fully evaluate the second argument 
> > before comparing to the first.  Since (range) is infinite, it hangs.
>
> Yes, that is what appears to be happening. The question is: why? Why does it 
> only do this to the second argument? Why does (= v s) for any vector `v' and 
> any infinite lazy sequence `s' not terminate, while (= s v) does?

Lazy sequences implement java.util.List, which has a .size method.
clojure.lang.APersistentVector/doEquiv (and doEquals) attempts to
optimize when it sees it is being compared to something with a .size
or .count method, by comparing sizes before doing the hard work of
comparing elements. But this is not much of an optimization when
the .size method is infinitely slow! Perhaps an additional test for
lazy sequences should be added to these methods, but I'm certain the
issue is more complicated than it appears after my cursory
exploration, so that may well have other issues.

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