[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: [RFC] Ranges - enable (10..-10)
From: "Christoph" <chr_news () gmx ! net>
Date: 2002-04-30 10:45:15
[Download RAW message or body]
"David Alan Black" <dblack@candle.superlink.net> wrote in
....
> In [ruby-talk:8993], matz said:
>
> The truth are:
>
> * A range enumeration cannot go back, it's upward only.
>
> * But A range with end point less than start point is valid.
>
> * Thus 1..-1 is a completely valid range object.
>
> * Array and String internally convert negative end point into
> size+n, where n is a negative number.
>
> * So range n..-m is interpreted as n..(size-m), thus works fine (if
> n <= (size-m)).
>
> I can't claim I've totally grasped why a range is upward by
> definition... but apparently it is, so that's *my* problem :-) You'll
You might find the following example somewhat enlighting?
---
class Class
alias succ superclass
end
p (Fixnum..Object).to_ary # => [Fixnum, Integer, Numeric, Object]
begin
(Fixnum..UnboundMethod) # Fixnum and UnboundMethod are not comparable
rescue ArgumentError => mes
p mes # => #<ArgumentError: bad value for range>
end
---
Given the fact that empty Ranges ala (1..-2) and (1...-2) are valid
construct, it
would makes to extend the Range construction and declare
(Fixnum..UnboundMethod).to_ary == [Fixnum, Integer, Numeric, Object]
(Fixnum..Float).to_ary == [Fixnum, Integer, Numeric]
# and
(Fixnum...UnboundMethod).to_ary == []
(Fixnum...Float).to_ary == []
# or (?)
(Fixnum...UnboundMethod).to_ary == [Fixnum, Integer, Numeric]
(Fixnum...Float).to_ary == [Fixnum, Integer]
Note I am not at all lobbying for such a behavioral change.
/Christoph
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic