We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexSuggestions & BugsWebsite,  Documentation,  Book Bugs › Possible Error on "arrayCopy" page
Page Index Toggle Pages: 1
Possible Error on "arrayCopy" page? (Read 1311 times)
Possible Error on "arrayCopy" page?
Jan 1st, 2010, 2:23pm
 
I'm wondering if there's an error on the "arrayCopy" page of the website documentation.
(...processing.org/reference/arrayCopy_.html)
If I'm wrong or if this is already known I apologize - I wasn't able to find any other threads about it.

The "arrayCopy" function isn't working properly for me. When I copied and pasted the first example code straight from the documentation into a sketch, it didn't give the correct output.

Code:
String[] north = { "OH", "IN", "MI"};
String[] south = { "GA", "FL", "NC"};
arrayCopy(north, south);
print(south);  // Prints OH, IN, MI

Output:
[Ljava.lang.String;@4845aa

My Question:

Does this function not work correctly any more or is it a problem on my end?  I running Processing 1.0.9, just downloaded the latest version today to be sure it wasn't the problem.  Also, I'm on Macintosh G5 PowerPC (not Intel) running OS 10.4.11

(Originally I couldn't get the "arrayCopy" function to work at all, so I really appreciate whoever wrote the error message saying to use "arraycopy" instead.  Thank you! Major kudos to whoever did that!)
Re: Possible Error on "arrayCopy" page?
Reply #1 - Jan 2nd, 2010, 1:47am
 
Pretty weird, how did that slip through. I wouldn't expect java or processing to 'know' how to print an array (not like ruby). It is also odd that processing supports a non camel case arraycopy!!!

Quote:
String[] states = {
  "OH", "Mich", "Main"};
String[] united = new String[3];

arraycopy(states, united);
for (int i = 0; i < states.length; i++)
{
  println(united[i]);
}

OH
Mich
Main






Apparently you should prefer the camel case version as the non-camel case has been deprecated (still works though and there is no warning!!!)
Re: Possible Error on "arrayCopy" page?
Reply #2 - Jan 2nd, 2010, 2:48pm
 
martin p, Processing knows how to print an array (single dimension only) by magic of reflection: it examines if the given object is an array, and if so, what kind of array it is, then iterate on length of the object to display the items.

Old arraycopy is indeed deprecated (marked as such in the ref doc) but not eliminated to ensure old sketches still work. A bit like framerate vs. frameRate except the latter generates a warning.

B Free, you have indeed found an error in the page, it should be println(south); not print().
Only println is smart about arrays...
Page Index Toggle Pages: 1