--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  , level  1;
   VALUE result, lv;

   rb_scan_args(argc, argv, "01", &lv);
   if (!NIL_P(lv)) level  UM2INT(lv);
   if (level 0) return ary;

   result  latten(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? ┐Áhat 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 <redmine / ruby-lang.org> 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  .flatten
>> a2 << :a
>> a2
> [1, 2, :a]
>> a
> [1, 2]
>
>> b  3, 4]
>> b2  .flatten 1
>> b2 << :b
>> b2
> [3, 4, :b]
>> b
> [3, 4]
>
> HOWEVER:
>
>> c  5, 6]
>> c2  .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:<br><br>static VALUE<br>rb_ary_flatten(intrgc, VALUE *argv, VALUE ary)<br>{<br> nt mod = 0, level = -1;<br> ALUE result, lv;<br><br> b_scan_args(argc, argv, &quot;01&quot;, &amp;lv);<br>

 f (!NIL_P(lv)) level = NUM2INT(lv);<br> f (level == 0) return ary;<br><br> esult = flatten(ary, level, &amp;mod);<br>A0 BJ_INFECT(result, ary);<br><br> eturn result;<br>}<br><br>In the line <br> if (level == 0) return ary;<br>

you will get the reference to the original array, instead of<br>a referenceo a clone.<br>The problem is: this is a bug or a feature? =D<br>That is, what is the behavior that we want when calling<br>flatten with 0, since this call doesn&#39;t make much sense.<br>

It is easy to fix it, but I don&#39;t know if I should. If you guys<br>think it is a good idea, that I can take some time to do that.<br>Bye!<br><br>Rafael Schouery<br>VidaGeek.net<br><br><br><br>On Wed, Apr 8, 2009 at 8:01 PM, Paul Lewis &lt;redmine / ruby-lang.org&gt; wrote:<br>

&gt; Bug #1367: flatten(0) is not consistent with flatten(), flatten(1), etc.<br>&gt; http://redmine.ruby-lang.org/issues/show/1367<br>&gt;<br>&gt; Author: Paul Lewis<br>

&gt; Status: Open, Priority: Normal<br>&gt; Category: core<br>&gt; ruby -v:uby 1.9.0 (2008-06-20 revision 17482) [i486-linux]<br>&gt;<br>&gt;&gt; a = [1, 2]<br>&gt;&gt; a2 = a.flatten<br>&gt;&gt; a2 &lt;&lt; :a<br>&gt;&gt; a2<br>

&gt; =&gt; [1, 2, :a]<br>&gt;&gt; a<br>&gt; =&gt; [1, 2]<br>&gt;<br>&gt;&gt; b = [3, 4]<br>&gt;&gt; b2 = b.flatten 1<br>&gt;&gt; b2 &lt;&lt; :b<br>&gt;&gt; b2<br>&gt; =&gt; [3, 4, :b]<br>&gt;&gt; b<br>&gt; =&gt; [3, 4]<br>

&gt;<br>&gt; HOWEVER:<br>&gt;<br>&gt;&gt; c = [5, 6]<br>&gt;&gt; c2 = c.flatten 0<br>&gt;&gt; c2 &lt;&lt; :c<br>&gt;&gt; c2<br>&gt; =&gt; [5, 6,c]<br>&gt;&gt; c<br>&gt; =&gt; [5, 6, :c] lt;-- Huh? hould be [5, 6].<br>

&gt;<br>&gt;<br>&gt; ----------------------------------------<br>&gt; http://redmine.ruby-lang.org<br>&gt;<br>&gt;<br><br>

--00163630e87f7b4251046789ed90--