Bug in newArray() macro function!?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug in newArray() macro function!?

Thorsten Sy
Hi,

perhaps I found an error in the new array-function or just did something wrong…

Here is my sample:

requires("1.45r");
  cars = newArray;
  cars[0] = "Saab";
  cars[1] = "Volvo";
  cars[2] = "BMW";
  cars[3] = "Ford";

  print("before adding")
  for (i=0; i<cars.length; i++)
      print(" \t" + cars[i]);
  print(" \t" + cars.length);

  cars = addCar(cars, "VW");

  print("\nafter adding")
  for (i=0; i<cars.length; i++)
      print(" \t" + cars[i]);
  print(" \t" + cars.length);


function addCar(autos, newCar) {
        autos[autos.length] = newCar;
return autos;
}


And here the printout:

before adding
  Saab
  Volvo
  BMW
  Ford
  4

after adding
  Saab
  Volvo
  BMW
  Ford
  VW
  undefined
  undefined
  7

And here is my question ;)

Where are the "undefined" values coming from?

Best regards,
Thorsten
Reply | Threaded
Open this post in threaded view
|

Re: Bug in newArray() macro function!?

Rasband, Wayne (NIH/NIMH) [E]
On Oct 17, 2011, at 11:38 AM, Thorsten Sy wrote:

> Hi,
>
> perhaps I found an error in the new array-function or just did something wrong…
>
> Here is my sample:
>
> requires("1.45r");
>  cars = newArray;
>  cars[0] = "Saab";
>  cars[1] = "Volvo";
>  cars[2] = "BMW";
>  cars[3] = "Ford";
>
>  print("before adding")
>  for (i=0; i<cars.length; i++)
>      print(" \t" + cars[i]);
>  print(" \t" + cars.length);
>
>  cars = addCar(cars, "VW");
>
>  print("\nafter adding")
>  for (i=0; i<cars.length; i++)
>      print(" \t" + cars[i]);
>  print(" \t" + cars.length);
>
>
> function addCar(autos, newCar) {
> autos[autos.length] = newCar;
> return autos;
> }
>
>
> And here the printout:
>
> before adding
> Saab
> Volvo
> BMW
> Ford
> 4
>
> after adding
> Saab
> Volvo
> BMW
> Ford
> VW
> undefined
> undefined
> 7
>
> And here is my question ;)
>
> Where are the "undefined" values coming from?

This bug is fixed in the ImageJ 1.45s daily build.

-wayne