How about having hashCode() on infinite sequences drill down into the
composite infinite sequences until we arrive at the generative
function?  Given that values are generated on demand, the generators
themselves can be compared.

To take from your fibs example:

hashCode(iterate f x) = hashCode(x) + (37 * (hashCode(fn) + (37 * base-
iterate-hash-value))

(Apologies for infix representation.)

Lazy-sequence functions that wrap the iterate call would have their
own hashCode() function call iterate's in a composite fashion.  This
way we avoid iterating over the values generated and instead derive
unique values for unique sequences.


On Oct 28, 3:55 am, John Harrop <jharrop...@gmail.com> wrote:
> and it's not hard to guess, and then prove, why:
>
> user=> (defn fibs [] (map first (iterate (fn [[a b]] [b (+ a b)]) [1 1])))
> #'user/fibs
> user=> (take 10 (fibs))
> (1 1 2 3 5 8 13 21 34 55)
> user=> (.hashCode 12)
> 12
> user=> (.hashCode "foo")
> 101574
> user=> (.hashCode (take 10 (fibs)))
> -1796812414
> user=> (.hashCode (fibs))
> <hangs>
>
> Probably the seq .hashCode should consider only the first N elements for
> some maximum N and if two longer (or even infinite) sequences collide so be
> it.

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