Why no decreasing enumerations?

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

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/.

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

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.

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

    (1..3).to_a #=> [1,2,3]

    ('a'..'c').to_a #=> ['a', 'b', 'c']

    [*1..3] #=> [1,2,3]

Just look at how all the methods work:

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

路路路

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

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.

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 ]