Project

General

Profile

Feature #18749

Updated by sawa (Tsuyoshi Sawada) almost 2 years ago

I came to think about this while looking at the pull request linked in #18748. 

 Currently, an endless inclusive range covers the corresponding endless exclusive range, but not vice versa: 

 ```ruby 
 ("a"..nil).cover?("a"...nil) #=> true 
 ("a"...nil).cover?("a"..nil) #=> false 

 (nil..nil).cover?(nil...nil) #=> true 
 (nil...nil).cover?(nil..nil) #=> false 
 ``` 

 This looks strange to me. There is not a single element covered by an endless inclusive range that is not covered by the corresponding endless exclusive range. This should mean that there is no difference in coverage between an endless inclusive range ranges and the corresponding endless exclusive range. ranges. 

 However, actually, an interval in mathematics (which I think is the counterpart to Ruby's range) ending in ∞ (which I think is the counterpart to an endless range) is always an open interval (which I think is the counterpart to an exclusive range), and never a closed interval (which I think is the counterpart to an inclusive range). 

 [a, ∞) is correct. 
 [a, ∞] is wrong. 

 From analogy, ideally, endless inclusive ranges should be prohibited in the first place. But that would cause new issues: There is no inclusive-exclusive distinction on the begin side of a range, and that is actually always assumed to be inclusive. Since we have beginless (inclusive) ranges, prohibiting endless inclusive ranges would cause asymmetry. 

 So what I can think of are the following possibilities (ordered from conservative to radical): 

 A. Endless inclusive ranges are allowed as is. An endless inclusive range and the corresponding endless exclusive range cover each other. 
 B. Endless inclusive ranges are disallowed. Beginless (inclusive) ranges are allowed as is. 
 C. New syntax is introduced in order to describe ranges that are exclusive on the begin side. Inclusive-exclusive distinction can be described on both begin and end sides independently. Endless inclusive ranges and beginless inclusive ranges are disallowed.

Back