[#407] New feature for Ruby? — Clemens.Hintze@...

Hi all,

27 messages 1999/07/01
[#413] Re: New feature for Ruby? — matz@... (Yukihiro Matsumoto) 1999/07/01

Hi Clemens,

[#416] Re: New feature for Ruby? — Clemens Hintze <c.hintze@...> 1999/07/01

On Thu, 01 Jul 1999, Yukihiro Matsumoto wrote:

[#418] Re: New feature for Ruby? — gotoken@... (GOTO Kentaro) 1999/07/01

Hi

[#426] Re: New feature for Ruby? — gotoken@... (GOTO Kentaro) 1999/07/02

Hi,

[#440] Now another totally different ;-) — Clemens Hintze <c.hintze@...>

Hi,

21 messages 1999/07/09
[#441] Re: Now another totally different ;-) — matz@... (Yukihiro Matsumoto) 1999/07/09

Hi,

[#442] Re: Now another totally different ;-) — Clemens Hintze <c.hintze@...> 1999/07/09

On Fri, 09 Jul 1999, you wrote:

[#443] — Michael Hohn <hohn@...>

Hello,

26 messages 1999/07/09
[#444] interactive ruby, debugger — gotoken@... (GOTO Kentaro) 1999/07/09

Hi Michael,

[ruby-talk:00407] New feature for Ruby?

From: Clemens.Hintze@...
Date: 1999-07-01 02:40:00 UTC
List: ruby-talk #407
Hi all,

I have begun to learn, how to extend Ruby using C. Doing that, I think
I can do some "real" work while learning.

As it has disturbes me several times, that a Range is only able to
iterate upwards but not downwards, I have chosen to add some features
to class Range and others, to let Range behave more like Smalltalk's
Intervall class.

So here are my ideas:

I would propose, that the class Range should behave more like the Interval
class of Smalltalk. That means it should be possible to do the
following:

- Range::new(1, 9)
- Range::new(1, 9, 2)
- Range::new(1, 9, -2) -- ERROR!
- Range::new(9, 1)
- Range::new(9, 1, 2)
- Range::new(9, 1, -2) -- ERROR!
- Range::new("a", "z", 3)
- Range::new(1.2, 2.9, 0.01)

As you can see, I would like to express the stepsize only via an
absolute value. The direction should only be given by "beg < end" or "beg
> end". I would raise an exception if the stepsize would be negativ, as
the general syntax should be:

   Range::new(beg, end, step=1)

That means the beginning ever comes first. If here I had a negative
stepsize, I would, probably, never reach my end.

The call "Range::new(1, 9)" or "Range::new(9, 1)" could also be
written as "1..9" and "9..1" (perhaps we could have a global function
"range" (like Python) which would instantiate Ranges via Range::new?).

Every class which wants to be used as Range, should implement a
"succ", "pred" and a "compare method" to enable us to detect the end
of iteration.

The "succ" and the "pred" method should be able to get an optional
argument describing the increment/decrement size. Whereas 5.succ(-2)
would be the same as 5.pred(2)! And vice versa.

Furthermore it would be nice to have a read-access function "[]", so
that the following would be possible:

   r = "a".."z"        # or Range::new("a", "z")
   print r[3]          # would print 'c'!

The special case would be the String class, as here the "succ" and the
"pred" functions would do a magic addition like in Perl. That means:

   "z".succ            # would deliver "aa"
   "aa".pred           # would deliver "z"

Please let me know your opinion! Is that all silly, or would you also
like such features?

Bye,
Cle.
--
this message is re-posted by matz the list admin.

In This Thread

Prev Next