From: Carlos Agarie Date: 2013-10-24T16:08:41-02:00 Subject: [ruby-core:58028] Re: [ruby-trunk - Feature #9049] Shorthands (a:b, *) for inclusive indexing --047d7b874c924ccded04e9808731 Content-Type: text/plain; charset=ISO-8859-1 > > 4) It is more intuitive for new Ruby programmers who come from a > Matlab/Octave/Python background. I'm not sure how much weight this reason > carries (maybe negative? :-)) I also contribute to NMatrix and I can guarantee that this is relevant, in a positive way. :) ----- Carlos Agarie Software Engineer @ Geekie (geekie.com.br) +55 11 97320-3878 @carlos_agarie 2013/10/24 David MacMahon > > On Oct 24, 2013, at 1:24 AM, Eregon (Benoit Daloze) wrote: > > > @david_macmahon What about (1..5).step(2).to_a ? > > The problem is that it creates a Range, and Enumerator, and an Array (plus > it's textually long). That's two extra objects compared to just creating a > Range and the Array could be very large. Which of the following would you > rather do? > > ```ruby > r = 1:12:1e6 # Create Range with step_size 12. > r[42] # Computes 1+12*42. > ``` > > or > > ```ruby > a = (1..1e6).step(12).to_a # Create Range, > # create Enumerator, > # and expand to largish Array. > a[42] # Get element 42 from the array. > ``` > > Dave > > --047d7b874c924ccded04e9808731 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
4) It is more intuitive for new Ruby programmers who com= e from a Matlab/Octave/Python background. =A0I'm not sure how much weig= ht this reason carries (maybe negative? :-))

I also contribute to NMatrix and I can guarantee that this is= relevant, in a positive way. :)


-----
Carlos Agarie
Soft= ware Engineer @ Geekie (= geekie.com.br)
+55 11 97320-3878
@carlos_agarie


2013/10/24 David MacMahon <davi= dm@astro.berkeley.edu>

On Oct 24, 2013, at 1:24 AM, Eregon (Benoit Daloze) wrote:

> @david_macmahon What about (1..5).step(2).to_a ?

The problem is that it creates a Range, and Enumerator, and an Array = (plus it's textually long). =A0That's two extra objects compared to= just creating a Range and the Array could be very large. =A0Which of the f= ollowing would you rather do?

```ruby
r =3D 1:12:1e6 # Create Range with step_size 12.
r[42] =A0 =A0 =A0 =A0# Computes 1+12*42.
```

or

```ruby
a =3D (1..1e6).step(12).to_a # Create Range,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# create Enumerator,=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# and expand to larg= ish Array.
a[42] =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Get element 42 from the = array.
```

Dave


--047d7b874c924ccded04e9808731--