mame (Yusuke Endoh) wrote:
-
(1..)
is semantically weird because it does not include the infinity.
(1..)
includes infinity. It's (1...) that doesn't include infinity.
(1..5).include? 5 #=> true
(1...5).include? 5 #=> false
For enumerators, it doesn't matter whether the end of an infinite range is included or not, because we'll never reach it. But for other operations, such as include?
, it matters.
Currently, we have:
(1..).include? Float::INFINITY #=> true
(1...).include? Float::INFINITY #=> true #### should be false?!
mame (Yusuke Endoh) wrote:
Also, ary[1..]
looks better than ary[1...]
.
All the valid indices of the array are finite, so there's no difference here. Just having ary[1..]
only would be fine.
sawa (Tsuyoshi Sawada) wrote (rewritten to use Unicode characters):
I agree with shevegen. In case one of the two is to be removed, it is 1..
that should be removed, not the other way around.
My understanding is that the ..
notation corresponds to the mathematical notation ]
(end of closed interval), whereas ...
corresponds to )
(end of open interval). And in mathematics, there is such thing as
[1, ∞)
but there is no such thing as
[1, ∞]
It is true that this is the convention followed in Mathematics. But in Ruby, we can easily write
(1...).include? Float::INFINITY
and the answer we get currently isn't consistent with Mathematics.