# Why no decreasing enumerations?

**URL:** <https://rubytalk.org/t/why-no-decreasing-enumerations/65074>\
**Category:** ruby-talk\
**Created:** [18 March 2012 19:17 UTC](https://rubytalk.org/t/why-no-decreasing-enumerations/65074 "2012-03-18T19:17:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_E](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@Jan\_E](https://rubytalk.org/u/Jan_E)\
**Post date:** [18 March 2012 19:17 UTC](https://rubytalk.org/t/why-no-decreasing-enumerations/65074/1 "2012-03-18T19:17:55Z")

</div>

Well, I'm glad for his objections. I don't think we need another PHP  
with all the data structures mixed together. 😉

Back on topic: I think it's actually a problem of mistakable syntax. It  
looks like a short notation of a sequence. Like you would write

2,4,...,10

in mathematics. In fact, Haskell has this kind of list notation:

[1..5] -- short for [1,2,3,4,5]

Many Ruby beginners try to write this down in Ruby, too. But in Ruby,  
the dot syntax describes a range, and a range isn't a sequence.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)\
**Post date:** [18 March 2012 19:57 UTC](https://rubytalk.org/t/why-no-decreasing-enumerations/65074/2 "2012-03-18T19:57:02Z")

</div>

> Well, I'm glad for his objections. I don't think we need another PHP  
> with all the data structures mixed together. 😉

I didn't say he did, not that "who knows".

> Back on topic: I think it's actually a problem of mistakable syntax. It  
> looks like a short notation of a sequence. Like you would write
> 
> 2,4,...,10
> 
> in mathematics. In fact, Haskell has this kind of list notation:
> 
> [1..5] -- short for [1,2,3,4,5]
> 
> Many Ruby beginners try to write this down in Ruby, too. But in Ruby,  
> the dot syntax describes a range, and a range isn't a sequence.

That is incorrect. Range is really more a sequence than it is an interval.

&nbsp;&nbsp;&nbsp;&nbsp;(1..3).each{ |i| p i }  
&nbsp;&nbsp;&nbsp;&nbsp;1  
&nbsp;&nbsp;&nbsp;&nbsp;2  
&nbsp;&nbsp;&nbsp;&nbsp;3

&nbsp;&nbsp;&nbsp;&nbsp;(1..3).to\_a #=\> [1,2,3]

&nbsp;&nbsp;&nbsp;&nbsp;('a'..'c').to\_a #=\> ['a', 'b', 'c']

&nbsp;&nbsp;&nbsp;&nbsp;[\*1..3] #=\> [1,2,3]

Just look at how all the methods work:

> **[Class: Range (Ruby 1.9.3)](https://ruby-doc.org/core-1.9.3/Range.html)**
>
> Class : Range - Ruby 1.9.3

Only `cover?` really expressly implies use as an interval.

> **···**
>
> On Sunday, March 18, 2012 3:17:55 PM UTC-4, Jan E. wrote:

---

<div class="post-metadata">

**Author:** ![11142](https://avatars.discourse-cdn.com/v4/letter/1/e0b2c6/32.png) [@11142](https://rubytalk.org/u/11142)\
**Post date:** [18 March 2012 20:18 UTC](https://rubytalk.org/t/why-no-decreasing-enumerations/65074/3 "2012-03-18T20:18:53Z")

</div>

Range is both a sequence and an interval, and this is deeply wrong.

Consider:

irb(main):008:0\> r = 'a'..'aa'  
=\> "a".."aa"  
irb(main):009:0\> r.to\_a  
=\> ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",  
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "  
x", "y", "z", "aa"]  
irb(main):010:0\> r.include? 'c'  
=\> true  
irb(main):011:0\> r.cover? 'c'  
=\> false

It's false. I don't know about you, but this seems quite  
counter-intuitive. #to\_a and #include? treat range as a sequence,  
#cover? as an interval. But it's just the beginning:

irb(main):012:0\> r = 'b'..'aa'  
=\> "b".."aa"  
irb(main):013:0\> r.to\_a  
=\>   
irb(main):014:0\> r.cover? 'c'  
=\> false  
irb(main):015:0\> r.include? 'c'  
=\> false

Explain these three to me, would you. I think this was some time ago  
reported to Ruby's bug tracker, the conclusion was that Range has a  
"feature" that if start compares as bigger than end, it won't bother  
generating the sequence - this obviously fails for many non-numeric  
ranges, as the one above. I don't think anything was done about it,  
though.

-- Matma Rex

> **···**
>
> 2012/3/18 Intransition \<transfire@gmail.com\>:
> 
> > That is incorrect. Range is really more a sequence than it is an interval.

---

<div class="post-metadata">

**Author:** ![Chad\_Perrin](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/chad_perrin/32/2234_2.png) [@Chad\_Perrin](https://rubytalk.org/u/Chad_Perrin)\
**Post date:** [18 March 2012 21:30 UTC](https://rubytalk.org/t/why-no-decreasing-enumerations/65074/4 "2012-03-18T21:30:00Z")

</div>

I dunno . . . I think it's a duck.

> **···**
>
> On Mon, Mar 19, 2012 at 05:18:53AM +0900, Bartosz Dziewoński wrote:
> 
> > 2012/3/18 Intransition \<transfire@gmail.com\>:  
> > \>  
> > \> That is incorrect. Range is really more a sequence than it is an interval.
> > 
> > Range is both a sequence and an interval, and this is deeply wrong.
> 
> --  
> Chad Perrin [original content licensed OWL: [http://owl.apotheon.org](http://owl.apotheon.org) ]
