Range#size, Range#length 
Author Message
 Range#size, Range#length

Apparently size and length are missing from
the Range class nowadays.

This surprises me a little. Is it because of
Float ranges or something?

I've made do with range.entries.size, which
works fine.

What's the rationale here? I'm curious.

Thanks,
Hal



Fri, 11 Nov 2005 04:53:53 GMT  
 Range#size, Range#length

Quote:

> Apparently size and length are missing from
> the Range class nowadays.

> This surprises me a little. Is it because of
> Float ranges or something?

> I've made do with range.entries.size, which
> works fine.

> What's the rationale here? I'm curious.

> [snip]

There was a lengthy discussion on the list about this a few months ago.  
The size of float ranges was one issue. Here's a length to one thread:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-
8&threadm=Pine.LNX.4.33.0302121350410.3138-
100000%40eli.fsl.noaa.gov&rnum=1&prev=/
groups%3Fq%3Druby%2Brange%2Blength%2Bsize%26hl%3Den%26lr%3D%26ie%3DUTF-
8%26oe%3DUTF-8%26sa%3DN%26tab%3Dwg

I think the decision comes down to saying that if you are using ranges  
as a form of constructor for an array, you should think of your range  
object in those terms -- i.e., explicitly call an iterator to count the  
number of entries.

The more I think about it, range is an unusual thing (very useful,  
memory efficient, but odd among Ruby objects in that it is really a  
function).



Fri, 11 Nov 2005 05:26:42 GMT  
 Range#size, Range#length

Quote:

> Apparently size and length are missing from
> the Range class nowadays.

> This surprises me a little. Is it because of
> Float ranges or something?

> I've made do with range.entries.size, which
> works fine.

> What's the rationale here? I'm curious.

You're right about the Float range part...
[ruby-talk:64479]:

Range serves purpose of both

  (a) sequence of values from beg to end (need "succ" to work)
  (b) interval from beg to end

When values are Strings, Range works as (a), whereas for Floats, it
works as (b), and both for Fixnum.

The reason I removed "length" and "size" from Range is that you cannot
tell which role a range takes.

--
 _           _                            
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
        Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

'Ooohh.. "FreeBSD is faster over loopback, when compared to Linux
over the wire". Film at 11.'
        -- Linus Torvalds



Fri, 11 Nov 2005 05:33:33 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. CW4 - Ranges question - changing range values while running

2. Range limits type : Range of values

3. * y for y in range(3) ] * x for x in range(2) ]

4. Array index range length ?

5. Range#size

6. Locator on Browse with Range limit : 'RANGE OF VALUES'

7. exponential range

8. coding a data range (second post attempt)

9. coding a date range

10. Slider range

11. Excel activex, setting multiple cells in a column range

12. DB Date Range Field Type

 

 
Powered by phpBB® Forum Software