www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - zip vs. lockstep -- problem when setting values

reply Joseph Rushton Wakeling <joseph.wakeling webdrake.net> writes:
Consider the following equivalent code using zip and lockstep respectively to
iterate over the entries in an array and set their values:

    auto arr1 = new double[10];
    foreach(i, ref x; zip(iota(10), arr1))
    {
        x = i;
    }
    writeln(arr1);

    auto arr2 = new double[10];
    foreach(i, ref x; lockstep(iota(10), arr2))
    {
        x = i;
    }
    writeln(arr2);

The first array will still be full of nan's when it is output, while the second
will have values set correctly.  Can anyone offer a reasonable explanation why
this should be so?  It looks like a bug to me, or at best an unreasonable
difference in functionality. :-(
Jun 28 2013
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 06/28/2013 06:19 AM, Joseph Rushton Wakeling wrote:
 Consider the following equivalent code using zip and lockstep respectively to
 iterate over the entries in an array and set their values:

      auto arr1 = new double[10];
      foreach(i, ref x; zip(iota(10), arr1))
      {
          x = i;
      }
      writeln(arr1);

      auto arr2 = new double[10];
      foreach(i, ref x; lockstep(iota(10), arr2))
      {
          x = i;
      }
      writeln(arr2);

 The first array will still be full of nan's when it is output, while the second
 will have values set correctly.  Can anyone offer a reasonable explanation why
 this should be so?  It looks like a bug to me, or at best an unreasonable
 difference in functionality. :-(
Looks like a bug and I can't find it in bugzilla. Ali
Jun 29 2013
parent Joseph Rushton Wakeling <joseph.wakeling webdrake.net> writes:
On 06/30/2013 02:16 AM, Ali Çehreli wrote:
 Looks like a bug and I can't find it in bugzilla.
Thanks for checking, Ali :-) I've added it: http://d.puremagic.com/issues/show_bug.cgi?id=10541
Jul 04 2013