Range#length?

Hi,

···

In message “Re: Range#length?!?!?” on 03/02/13, Hugh Sasse Staff Elec Eng hgs@dmu.ac.uk writes:

This has always puzzled me, that
the longer gap (‘…’ vs ‘…’) is the shorter interval, but it’s way
too late to change now, and knowing what I know of Matz’s work,
there’s going to be a VERY good reason for this!

Unfortunately not for this case. “…” was there first, so only “…”
was available when I wanted end excluding range. I made up the reason
that “… would be used more often, so that it should be shorter”, but
I myself does not feel this is very good reason.

						matz.

Hi,

Interesting.

is that good, or bad? :wink:

Neutral.

i guess the question is WHAT a Range of strings is :

  • all possible comibnations between start and end
  • a linear (succ) progression between start and end

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.

for x in 0.0 … 42.0

end

stops.

confused ??

irb(main):001:0> for x in 0.0 … 42.0; end
TypeError: cannot iterate from Float
from (irb):1:in `each’
from (irb):1

Sorry, it used to be possible. I forget the change I did.

						matz.
···

In message “Re: Range#length?!?!?” on 03/02/12, ahoward ahoward@fsl.noaa.gov writes:

But then, for “range” itself you get results including:

  1. The maximum extent or distance limiting operation, action, or
    […]

touche! :wink:

i think it’s not quite fair though, as Range is defined as a SET of values in
the pickaxe (which, let’s face it, is essentially a language specification to
most of us).

It is used that way, but it is a description of what exists, rather
than the basis for the language design. Is ‘post hoc’ the phrase
here?

each of which include “distance” in the definition of range.
range.distance would mean the distance of the distance? :slight_smile:

by that logic ‘distance.size’ does not make much sense either.

You can talk about the size of a distance, if it is small or
large… Maybe Range.length? Does this really mean we need
another mixin like Enumearable called Differencable (not to be
confused with differentiable, which implies calculus!) so that
things which can be ordered but not subtracted and things which can
be ordered AND subtracted behave appropriately? This use of
length() might (cognitively) interfere with Array.length, though.
Range.span(), perhaps?

Except that floats aren’t reals, so are not infinitely precise, so
there is a finite number between two values.

technically, with today’s technology yes. abstractly though, they ARE reals
and nearly always have that semantic meaning. if their finiteness could be
counted on, they would be used to control for loops, but no one does that do
they?

No, but it would allow some resolution to this without getting into
orders of infinity. But it would be up to Matz, and there is a
stronger case for “pretending” they ARE reals.

Ranges can be constructed using objects of any type, as long as the objects
can be compared using their <=> operator and they support the succ method to
return the next object in sequence.

so a Range HAS a start and end, but it IS a SET. all that is required to be a
set is to implement <=> and succ, which Floats do. using your logic what

Really?

you are correct - but i was merely quoting the pickaxe. the point was that

Yes, but I was surprised by this reference to succ, didn’t notice it
in this way before. I think this is possibly an overspecification
for what a range is, given the float case, though any other
description would complicate the text somewhat.

their is no implication that the objects in a Range support ‘+’ or ‘-’, etc.
rather the implication is only that they are an ordered set - nothing more -
and ordered does not imply finite nor the applicability of mathmatical
operators.

Agreed.

    [...]

surely it should be ‘just a little’ bigger than (0.0 … 42.0).size right?

smaller. … excludes the end. This has always puzzled me, that
the longer gap (‘…’ vs ‘…’) is the shorter interval, but it’s way
too late to change now, and knowing what I know of Matz’s work,
there’s going to be a VERY good reason for this!

again, i miswrote (only ONE cup of cafe so far!) but we are on the same page

No problem, just thought it might help to flag this up as I keep
making this particular mistake. “Experience is the ability to
recognise a mistake when you make it again” to quote
/usr/games/fortune.

here. you didn’t address the question though - iff a range of floats is NOT
Infinity then what would the return value be for

(0.0 … 42.0).size

and

(0.0 … 42.0).size

it is impossible to define size using ‘-’ and have this make any sort of
sense since (0.0 … 42.0) > (0.0 … 42.0)!

This is like open and closed sets. If the range is a set, then you
know what the largest value in the set is, in the first case it is
42.0, in the second it is something a bit smaller which is probably
architecture dependent. It might not be a useful value to obtain,
but it still has meaning. How the machine obtains this value is
another thing – it would be silly to represent a Float range as a
lump of virtual memory with all those floats in it, “Oh, and throw
away the 42.0 – we don’t need that!”. Also this is complicated
because the space between two floats will change as the magnitude
gets large. “The devil is in the detail”.

-a

    Hugh
···

On Thu, 13 Feb 2003, ahoward wrote:

On Thu, 13 Feb 2003, Hugh Sasse Staff Elec Eng wrote:

Hi,

This has always puzzled me, that
the longer gap (‘…’ vs ‘…’) is the shorter interval, but it’s way
too late to change now, and knowing what I know of Matz’s work,
there’s going to be a VERY good reason for this!

Unfortunately not for this case. “…” was there first, so only “…”

The very good reason might be the historical one for choosing ‘…’
in the first place, based on the linguistic heritage of ruby. I
don’t know CLU, CLOS, or SmallTalk well, so that may be it.

was available when I wanted end excluding range. I made up the reason
that “… would be used more often, so that it should be shorter”, but
I myself does not feel this is very good reason.

I think that’s good enough, given the constraints of ASCII :slight_smile:
When Unicode is established for 20 years there’ll be lots more
choice!

  					matz.
    Hugh
···

On Thu, 13 Feb 2003, Yukihiro Matsumoto wrote:

In message “Re: Range#length?!?!?” > on 03/02/13, Hugh Sasse Staff Elec Eng hgs@dmu.ac.uk writes:

Hi,

How about “sup” and “inf”? Using ‘{}’ notation for set, ‘()’ for open
interval, and ‘’ for closed internval, then

{40, 41, 42}   .sup   >> 42
(40.0, 42.0)   .sup   >> 42.0
[40.0, 42.0]   .sup   >> 42.0

Regarding the “length” or “size” of a floating point range, I guess we can
decide which is more useful from programming point of view, whether to
return infinity (aleph one, actually, according to the Continuum
Hypothesis) or to return Range.sup - Range.inf (which is more in line with
the Measure Theory).

Regards,

Bill

···

ahoward ahoward@fsl.noaa.gov wrote:

On Tue, 11 Feb 2003, Vraj Mohan wrote:

Yukihiro Matsumoto wrote:

Hi,

Do you think of a good name for it? I’m glad to add a method if
you have a good name.

  					matz.

How about “last_member”?

what would be the last_member of

(0.0 … 42.0) ??

I would rationalize it this way: … works the same as
in Pascal (the only language I know that also has this
construct, though there are probably others). So the
newer behavior gets the newer syntax (…).

Maybe two weak reasons can be combined to make
a stronger one… :wink:

Hal

···

----- Original Message -----
From: “Yukihiro Matsumoto” matz@ruby-lang.org
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, February 12, 2003 9:48 AM
Subject: Re: Range#length?!?!?

Hi,

In message “Re: Range#length?!?!?” > on 03/02/13, Hugh Sasse Staff Elec Eng hgs@dmu.ac.uk writes:

This has always puzzled me, that
the longer gap (‘…’ vs ‘…’) is the shorter interval, but it’s way
too late to change now, and knowing what I know of Matz’s work,
there’s going to be a VERY good reason for this!

Unfortunately not for this case. “…” was there first, so only “…”
was available when I wanted end excluding range. I made up the reason
that “… would be used more often, so that it should be shorter”, but
I myself does not feel this is very good reason.

The key to remembering is to find a handy mnemonic for “..” VS “…”.
This is the one I use.

(start..end) includes end
The extra dot in (start…end) “pushes” the end value outside the
range.

Ok, it’s kinda stupid. But sometimes the stupid mnemonics work the
best.

···

On Wed, 2003-02-12 at 10:48, Yukihiro Matsumoto wrote:

Hi,

In message “Re: Range#length?!?!?” > on 03/02/13, Hugh Sasse Staff Elec Eng hgs@dmu.ac.uk writes:

This has always puzzled me, that
the longer gap (‘..’ vs ‘…’) is the shorter interval, but it’s way
too late to change now, and knowing what I know of Matz’s work,
there’s going to be a VERY good reason for this!

Unfortunately not for this case. “..” was there first, so only “…”
was available when I wanted end excluding range. I made up the reason
that “.. would be used more often, so that it should be shorter”, but
I myself does not feel this is very good reason.


– Jim Weirich jweirich@one.net http://w3.one.net/~jweirich

“Beware of bugs in the above code; I have only proved it correct,
not tried it.” – Donald Knuth (in a memo to Peter van Emde Boas)

Unless they expand the keyboard we’ll be using the same characters to
program.

···

On Thu, Feb 13, 2003 at 02:23:17AM +0900, Hugh Sasse Staff Elec Eng wrote:

I think that’s good enough, given the constraints of ASCII :slight_smile:
When Unicode is established for 20 years there’ll be lots more
choice!


_ _

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

The documentation is in Japanese. Good luck.
– Rich $alz

Hi,

···

In message “Re: Range#length?” on 03/02/13, William Djaja Tjokroaminata billtj@y.glue.umd.edu writes:

How about “sup” and “inf”? Using ‘{}’ notation for set, ‘()’ for open
interval, and ‘’ for closed internval, then

{40, 41, 42} .sup >> 42
(40.0, 42.0) .sup >> 42.0
[40.0, 42.0] .sup >> 42.0

I’m not sure what “sup” and “inf” stand for.

						matz.

I find it very acceptable and moreover that’s the same I thought of :slight_smile:

···

On Thu, Feb 13, 2003 at 11:23:35AM +0900, Jim Weirich wrote:

The key to remembering is to find a handy mnemonic for “…” VS “…”.
This is the one I use.

(start…end) includes end
The extra dot in (start…end) “pushes” the end value outside the
range.

Ok, it’s kinda stupid. But sometimes the stupid mnemonics work the
best.


_ _

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

Turn right here. No! NO! The OTHER right!

"Yukihiro Matsumoto" <matz@ruby-lang.org> February 12, 2003 at 9:48 AM

wrote:

This has always puzzled me, that the longer gap ('..' vs '...') is the

shorter interval, but it's way too late to change now, and knowing what I
know of Matz's work, there's going to be a VERY good reason for this!

Unfortunately not for this case. ".." was there first, so only "..."

was available when I wanted end excluding range. I made up the reason that
".. would be used more often, so that it should be shorter", but I myself
does not feel this is very good reason.

I would rationalize it this way: .. works the same as in Pascal (the only

language I know that also has this construct, though there are probably
others). So the newer behavior gets the newer syntax (...).

Maybe two weak reasons can be combined to make a stronger one... :wink:

I remember it as, the third dot generally is a placeholder for the highest
inclusive value of the range.

With kind regards,

···

"Hal E. Fulton" <hal9000@hypermetrics.com> Feb 13, 2003 at 06:45 AM wrote:

on 03/02/13, Hugh Sasse Staff Elec Eng <hgs@dmu.ac.uk> writes:

In article 1045093515.872338.8431.nullmailer@picachu.netlab.jp,

Hi,

How about “sup” and “inf”? Using ‘{}’ notation for set, ‘()’ for open
interval, and ‘’ for closed internval, then

{40, 41, 42} .sup >> 42
(40.0, 42.0) .sup >> 42.0
[40.0, 42.0] .sup >> 42.0

I’m not sure what “sup” and “inf” stand for.

  					matz.

For me, the right way to think about a range you can iterate over is a a
nice compact notation/implementation for a particular kind of array.
After all,

(0…5).each { |i| …

has the same effect as

[0,1,2,3,4,5].each {|i| …

and

(0…5).each { |i| …

has the same effect as

[0,1,2,3,4].each {|i| …

so it is clear to me that one should have:

(0…5).length == 6
(0…5).length == 5
(0…5).max == 5
(0…5).max == 4
(0…5).min == 0

etc…
For me, this kind of equivalence with arrays
(1) suppresses the need to invent new method names
(2) makes ranges more useful (applicable in more situations).

Now, I will not comment on suitable methods for ranges you cannot
iterate over (float ranges?). But the above is my philosophy on suitable
methods for ranges you can iterate over.

What do you think?

···

Yukihiro Matsumoto matz@ruby-lang.org wrote:

In message “Re: Range#length?” > on 03/02/13, William Djaja Tjokroaminata billtj@y.glue.umd.edu writes:

Hi Matz,

I was taking the point from ahoward, which said

"what would be the last_member of (0.0 ... 42.0) ??"

In any Advanced Calculus or Real Analysis course, they introduced the
concept of “Supremum” (sup) which is the smallest upper bound and
“Infinum” (inf) which is the greatest lower bound. A smallest upper bound
that belongs to the set is also called Maximum, and similarly, a greatest
lower bound that belongs to the set is also called Minimum.

Therefore, (0.0 … 42.0).max == 42.0 but (0.0 … 42.0).max does not
exist. However, (0.0 … 42.0).sup and (0.0 … 42.0).sup both exist and
are equal to 42.0.

For a quick, more formal treatment of the subject, we can read e.g.

http://www.math.purdue.edu/~rcp/11_sup-inf_public.pdf

I am sorry if I am being too formal mathematically; I was only responding
to ahoward’s points.

Regards,

Bill

···

Yukihiro Matsumoto matz@ruby-lang.org wrote:

Hi,

In message “Re: Range#length?” > on 03/02/13, William Djaja Tjokroaminata billtj@y.glue.umd.edu writes:

How about “sup” and “inf”? Using ‘{}’ notation for set, ‘()’ for open
interval, and ‘’ for closed internval, then

{40, 41, 42} .sup >> 42
(40.0, 42.0) .sup >> 42.0
[40.0, 42.0] .sup >> 42.0

I’m not sure what “sup” and “inf” stand for.

  					matz.

Hi --

···

On Sat, 5 Feb 2005, georgesawyer wrote:

"Hal E. Fulton" <hal9000@hypermetrics.com> Feb 13, 2003 at 06:45 AM wrote:

"Yukihiro Matsumoto" <matz@ruby-lang.org> February 12, 2003 at 9:48 AM

wrote:

on 03/02/13, Hugh Sasse Staff Elec Eng <hgs@dmu.ac.uk> writes:

This has always puzzled me, that the longer gap ('..' vs '...') is the

shorter interval, but it's way too late to change now, and knowing what I
know of Matz's work, there's going to be a VERY good reason for this!

Unfortunately not for this case. ".." was there first, so only "..."

was available when I wanted end excluding range. I made up the reason that
".. would be used more often, so that it should be shorter", but I myself
does not feel this is very good reason.

I would rationalize it this way: .. works the same as in Pascal (the only

language I know that also has this construct, though there are probably
others). So the newer behavior gets the newer syntax (...).

Maybe two weak reasons can be combined to make a stronger one... :wink:

I remember it as, the third dot generally is a placeholder for the highest
inclusive value of the range.

My mneumonic is:

   .. has two letters, so the upper value is "in"
   ... has three, so the upper value is "out"

:slight_smile:

David

--
David A. Black
dblack@wobblini.net

i am totally with you. i see no reason why ALL ranges must behave in exactly
the same way, i find it perfectly acceptable that and infinitely sized range
(floats) would not be a good thing to iterate over! this for exactly the same
reason that we do not control for loops in C with floats. also, certain types
of objects, like Strings, can have a meaningfull interation in support of
POLS, for example (see my post regarding treating String Ranges as base 256
numbers to easily calculate the size)

( ‘abc’ … ‘abf’).each do |word|
p word
end

should, IMHO, output

‘abc’
‘abd’
‘abe’
‘abf’

which CAN be accomplished using succ, but breaks when the starting string
cannot reach the ending string. so, here is my suggestion :

similarly to succ, all Enumerable objects must support a ‘range_next’ method
which has this signature

def range_next endpoint
  ...
end

this would simply be an alias to succ for Fixnum, but for more complex
types, like Floats or Strings a next which always reaches the end can be
defined to allow

( 'shorter' .. 'a bit longer' ).each do |word|
  ...
end

which could then easily generate EVERY word which is both greater than
‘shorter’ but less than ‘a bit longer’ (again, see my post regarding
treating strings as b256 numbers for how this is easily done)

thoughts?

-a

···

On Thu, 13 Feb 2003, Jean Michel wrote:

Now, I will not comment on suitable methods for ranges you cannot
iterate over (float ranges?). But the above is my philosophy on suitable
methods for ranges you can iterate over.

What do you think?

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

This is mathematically sound, but in which context would you use it?

All our problems come from trying to define ranges over compact metric
spaces (although floats really aren’t). A way to differentiate would be
introducing a new notation

‘a’…‘b’ ‘a’…‘b’
1.0 – 2.0 1.0 — 2.0 compact
and warnings when Ruby realizes you’re mistaken in your choice of range.
They easiest way to find whether ‘…’ or ‘–’ are right would be testing
for #succ.

This is however ugly and I’d stay with what we have now.

···

On Thu, Feb 13, 2003 at 01:07:37PM +0900, William Djaja Tjokroaminata wrote:

Hi Matz,

I was taking the point from ahoward, which said

"what would be the last_member of (0.0 ... 42.0) ??"

In any Advanced Calculus or Real Analysis course, they introduced the
concept of “Supremum” (sup) which is the smallest upper bound and
“Infinum” (inf) which is the greatest lower bound. A smallest upper bound
that belongs to the set is also called Maximum, and similarly, a greatest
lower bound that belongs to the set is also called Minimum.

Therefore, (0.0 … 42.0).max == 42.0 but (0.0 … 42.0).max does not
exist. However, (0.0 … 42.0).sup and (0.0 … 42.0).sup both exist and
are equal to 42.0.

For a quick, more formal treatment of the subject, we can read e.g.

http://www.math.purdue.edu/~rcp/11_sup-inf_public.pdf

I am sorry if I am being too formal mathematically; I was only responding
to ahoward’s points.


_ _

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

<|ryan|> I don’t use deb
u poor man
netgod: heh
apt-get install task-p0rn

I think of the third dot as the "exclude end" switch (:

martin

···

David A. Black <dblack@wobblini.net> wrote:

My mneumonic is:

   .. has two letters, so the upper value is "in"
   ... has three, so the upper value is "out"

Hi,

···

In message “Re: Range#length?” on 03/02/13, ahoward ahoward@fsl.noaa.gov writes:

( ‘abc’ … ‘abf’).each do |word|
p word
end

should, IMHO, output

‘abc’
‘abd’
‘abe’
‘abf’

which CAN be accomplished using succ, but breaks when the starting string
cannot reach the ending string. so, here is my suggestion :

Range uses String#upto which terminates loop when generated string is
longer than endpoint string.

						matz.

Hi batsman,

I don’t know. I think it is the right way to say the upper bound of a
range when the end points are floats. Is the current concensus to support
a range of floats or are we going to drop range of floats altogether in a
future version or Ruby (and retain only range of integers, and chars,
possibly)?

Regards,

Bill

···

Mauricio Fern?ndez batsman.geo@yahoo.com wrote:

This is mathematically sound, but in which context would you use it?