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.
Page Index Toggle Pages: 1
Did "join" get broken? (Read 1569 times)
Did "join" get broken?
Jun 6th, 2005, 3:54pm
 
Hi all.

Having some issues porting code from alpha.  Did the "join" command get broken since alpha?

This is the REFERENCE text from the website:

// works identically with float[] and String[]
int list[] = new list[3];
list[0] = 8;
list[1] = 67;
list[2] = 5;
String formatted = join(list, ", ");
// formatted now contains "8, 67, 5"


There is a typo in the above.  This version works in alpha:


// works identically with float[] and String[]
int list[] = new INT [3];
list[0] = 8;
list[1] = 67;
list[2] = 5;
String formatted = join(list, ", ");
// formatted now contains "8, 67, 5"


However, it doesn't work in BETA (0087).  I think this is partly because 'list' has become a declared variable or somesuch, but also it seems that "join" works for Strings but is now broken for joining any array of ints or floats.

For example:

int myList[] = new int[3];
myList[0] = 8;
myList[1] = 67;
myList[2] = 5;
String formatted = join(myList, ", ");


Yields:


C:/..../Application Data/Processing/build/Temporary_7986_4172.java:7:20:7:37: Semantic Error: No applicable overload for a method with signature "join(int[], java.lang.String)" was found in type "processing.core.PApplet". Perhaps you wanted the overloaded version "java.lang.String join(java.lang.String[] $1, java.lang.String $2);" instead?



Similarly the reference float example doesn't work:

float f[] = new float[3];
f[0] = 1.3;
f[1] = 92.8;
f[2] = 0.7;
// 3 digits on the left of the decimal point
// 2 digits to the right of the decimal point
String zerofloats = join(f, " ", 3, 2);


Yields:


C:/...../Application Data/Processing/build/Temporary_6114_4672.java:7:21:7:38: Semantic Error: No applicable overload for a method with signature "join(float[], java.lang.String, int, int)" was found in type "processing.core.PApplet". Perhaps you wanted the overloaded version "java.lang.String join(java.lang.String[] $1, java.lang.String $2);" instead?


Or has this been spotted already?  Might be worth changing the reference text to not use "list" either way...

TC,

R
Re: Did "join" get broken?
Reply #1 - Jun 6th, 2005, 11:02pm
 
sounds like it only works on Strings, not on ints/floats, as opposed to using the word list.
Looks like the join function needs an overload that converts ints/floats, too. To fix it, just convert the number to a String before joining.
Re: Did "join" get broken?
Reply #2 - Jun 7th, 2005, 3:10am
 
hm, that was something that changed between 68 and 69 actually but i guess didn't get documented/updated properly.

join() only works on strings, but you can use nf() on a list of ints or floats to convert them to a String array. so the ref should read:

Code:
// works identically with float[] and String[]  
int list[] = new int[3];
list[0] = 8;
list[1] = 67;
list[2] = 5;
String formatted = join(nf(list, 0), ", ");
// formatted now contains "8, 67, 5"
println(formatted);


and the second one, which makes the reasoning behind the api change a little clearer (why have multiple versions of both nf and join?) should look like this:

Code:
float f[] = new float[3];  
f[0] = 1.3;
f[1] = 92.8;
f[2] = 0.7;
// 3 digits on the left of the decimal point
// 2 digits to the right of the decimal point
String zerofloats = join(nf(f, 3, 2), " ");
println(zerofloats);

Re: Did "join" get broken?
Reply #3 - Jun 25th, 2005, 12:07am
 
This documentation persisted suprisingly long after the functionality changed. It's updated now and will be online shortly. I'm sorry about this.

Casey

Page Index Toggle Pages: 1