From: Rafael Crivellari Saliba Schouery Date: 2009-04-15T05:46:42+09:00 Subject: [ruby-core:23207] Re: [Bug #1367] flatten(0) is not consistent with flatten(), flatten(1), etc. --00163630e87f7b4251046789ed90 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit I did take a look in the problem: static VALUE rb_ary_flatten(int argc, VALUE *argv, VALUE ary) { int mod = 0, level = -1; VALUE result, lv; rb_scan_args(argc, argv, "01", &lv); if (!NIL_P(lv)) level = NUM2INT(lv); if (level == 0) return ary; result = flatten(ary, level, &mod); OBJ_INFECT(result, ary); return result; } In the line if (level == 0) return ary; you will get the reference to the original array, instead of a reference to a clone. The problem is: this is a bug or a feature? =D That is, what is the behavior that we want when calling flatten with 0, since this call doesn't make much sense. It is easy to fix it, but I don't know if I should. If you guys think it is a good idea, that I can take some time to do that. Bye! Rafael Schouery VidaGeek.net On Wed, Apr 8, 2009 at 8:01 PM, Paul Lewis wrote: > Bug #1367: flatten(0) is not consistent with flatten(), flatten(1), etc. > http://redmine.ruby-lang.org/issues/show/1367 > > Author: Paul Lewis > Status: Open, Priority: Normal > Category: core > ruby -v: ruby 1.9.0 (2008-06-20 revision 17482) [i486-linux] > >> a = [1, 2] >> a2 = a.flatten >> a2 << :a >> a2 > => [1, 2, :a] >> a > => [1, 2] > >> b = [3, 4] >> b2 = b.flatten 1 >> b2 << :b >> b2 > => [3, 4, :b] >> b > => [3, 4] > > HOWEVER: > >> c = [5, 6] >> c2 = c.flatten 0 >> c2 << :c >> c2 > => [5, 6, :c] >> c > => [5, 6, :c] <-- Huh? Should be [5, 6]. > > > ---------------------------------------- > http://redmine.ruby-lang.org > > --00163630e87f7b4251046789ed90 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I did take a look in the problem:

static VALUE
rb_ary_flatten(int= argc, VALUE *argv, VALUE ary)
{
=A0 =A0int mod =3D 0, level =3D -1;=
=A0 =A0VALUE result, lv;

=A0 =A0rb_scan_args(argc, argv, "= ;01", &lv);
=A0 =A0if (!NIL_P(lv)) level =3D NUM2INT(lv);
=A0 =A0if (level =3D=3D = 0) return ary;

=A0 =A0result =3D flatten(ary, level, &mod);
= =A0 =A0OBJ_INFECT(result, ary);

=A0 =A0return result;
}

= In the line
=A0 if (level =3D=3D 0) return ary;
you will get the reference to the original array, instead of
a reference= to a clone.
The problem is: this is a bug or a feature? =3DD
That is= , what is the behavior that we want when calling
flatten with 0, since t= his call doesn't make much sense.
It is easy to fix it, but I don't know if I should. If you guys
thin= k it is a good idea, that I can take some time to do that.
Bye!

R= afael Schouery
VidaGeek.net



On Wed, Apr 8, 2009 at 8:01 P= M, Paul Lewis <redmine@ruby-lan= g.org> wrote:
> Bug #1367: flatten(0) is not consistent with flatten(), flatten(1), et= c.
> http:/= /redmine.ruby-lang.org/issues/show/1367
>
> Author: Paul Le= wis
> Status: Open, Priority: Normal
> Category: core
> ruby -v:= ruby 1.9.0 (2008-06-20 revision 17482) [i486-linux]
>
>> a = =3D [1, 2]
>> a2 =3D a.flatten
>> a2 << :a
>&= gt; a2
> =3D> [1, 2, :a]
>> a
> =3D> [1, 2]
>
>= ;> b =3D [3, 4]
>> b2 =3D b.flatten 1
>> b2 << := b
>> b2
> =3D> [3, 4, :b]
>> b
> =3D> [= 3, 4]
>
> HOWEVER:
>
>> c =3D [5, 6]
>> c2 =3D c= .flatten 0
>> c2 << :c
>> c2
> =3D> [5, 6,= :c]
>> c
> =3D> [5, 6, :c] =A0<-- Huh? =A0Should be [= 5, 6].
>
>
> ----------------------------------------
> http://redmine.ruby-lang.org
>= ;
>

--00163630e87f7b4251046789ed90--