On Sep 21, 2007, at 8:14 AM, Sebastian Hungerecker wrote: > Xavier Noria wrote: >> I guess the claim that well-defined infinite Ranges in Ruby are >> implementable is now clear. > > Sorry if this is a stupid question, but couldn't you just have > proved that > claim by giving 1..(1.0/0) as an example? That's an infinite range > right > there and you don't have to define any custom classes. Or would you > say that doesn't qualify as well-defined? Exactly, thank you, let me write 1.0/0 as w to simplify the notation in what follows. That is the basic idea I had in mind when I mentioned an alternative proof involving N and a few infinities. Note that technically you still need to define a class, because you need 1, and w to belong to the same class, and have #<=> and #succ defined for both ("have" in the context of this thread). It is true that w.succ is not _needed_ to implement Range#length, but the rules I am playing with require your objects to respond to a couple of methods, that includes the endpoints. Thus, you need to define w.succ and w.succ.succ in turn, and so on. The result is another handful of "naturals" past w. We can write them like this (note this is just intuitive notation, we have not defined addition for w): w, w + 1, w + 2, w + 3, .... You'd expect as well that "<" (which means <=> gives -1) satisfies w < w.succ (:= w + 1) < w.succ.succ (:= w + 2) < .... Right, keep the ordinary ordering for the naturals. Let's define all naturals to be strictly less than w + n for all n, and define w + n <=> w + m iff n <=> m. That <=> works. So yes, that was the idea but needs a bit of extra work to follow the docs. I came with the ZSquared example (I prefer the second version) to avoid more math-like stuff and still have both methods implemented in the class, and with easy one-liners. You can visualize ZSquared in Z x Z if you want, but people can understand ZSquared gives an infinite Range just reasoning about arrays of integers otherwise. Thus, even if Range required in practice that objects implemented #succ, Range#length is not guaranteed to terminate in general written as a loop over #succ. Thank you Sebastian, -- fxn