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.
IndexProgramming Questions & HelpSyntax Questions › Newbie: Call ByValue / Call by Reference
Page Index Toggle Pages: 1
Newbie: Call ByValue / Call by Reference? (Read 3039 times)
Newbie: Call ByValue / Call by Reference?
Dec 20th, 2009, 2:55am
 


Hello,

I  have a small Newbie-Question here.

Normally I can call a function
float CalculateSomething (x,y) {
...
return (MyVar);
}

How can I return more than one value?

Let's say I also want to modify x and y.

In Basic this can be done via
Call ByValue / Call by Reference.

Is it possible in processing?

This would be a nice entry on the learning pages.

Thanks!

Happy Christmas!

Greetings,

Chris


Re: Newbie: Call ByValue / Call by Reference?
Reply #1 - Dec 20th, 2009, 4:40am
 
hi Chris,
processing is just like java. so you can look for tutorial pages about that. you cant return more then one variable/object. but you can return an array or another datatype which include more variables.
if you use the standarddatatypes like int,flaot,boolean it is always call by value. If you have Object Parameters like Integer,Float,Boolean,.... which are wrapper classes of the standarddadattypes its always call by reference. i think its like this. give it a try.
Re: Newbie: Call ByValue / Call by Reference?
Reply #2 - Dec 20th, 2009, 5:04am
 
http://processing.org/discourse/yabb2/?num=1261136027
Re: Newbie: Call ByValue / Call by Reference?
Reply #3 - Dec 20th, 2009, 11:28pm
 
ramin wrote on Dec 20th, 2009, 4:40am:
Object Parameters [are] always call by reference.

No. Even if I thought that too for quite some time... Wink
Compiler purists insist to say that Java always pass parameters by value.
You can alter the values inside an object (including arrays) passed by parameter, but you can't change the object itself, eg. by creating a new object and replacing the one passed as parameter with the new one: the reference to the object remains unaltered.

[EDIT] Re-reading the thread pointed out by JR, I see that he explained that already... Smiley
Well, repetition, by various voices, is the mother of pedagogy!  Roll Eyes
Page Index Toggle Pages: 1