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 › print the name of a variable
Page Index Toggle Pages: 1
print the name of a variable (Read 354 times)
print the name of a variable
Jan 19th, 2009, 5:13pm
 
hi

i am trying to print the name of a variable. either it is totally simple and i dont get it or, well help me out.

for my sketch i wanted to make a small debug function where instead of a normal println(incrementVariable) it not just prints the value of a variable but also the name with it like:

incrementVariable: 10

is this possible, am i not getting it?
thanks
fakob

Re: print the name of a variable
Reply #1 - Jan 19th, 2009, 6:42pm
 
It is not possible (at least in a simple, automated way).
Of course, you can do:
println("incrementVariable: " + incrementVariable);
A bit heavy-handed but usable.
Re: print the name of a variable
Reply #2 - Jan 19th, 2009, 7:18pm
 
thanks for the reply, PhiLho.
too bad i have to hardcode it. i remember that it is possible in python, but i cant remember how. anyway thanks for the answer.
Re: print the name of a variable
Reply #3 - Jan 19th, 2009, 9:26pm
 
Maybe it is possible by reflexion or with the debug interface, although I don't know how...
Re: print the name of a variable
Reply #4 - Jan 19th, 2009, 10:06pm
 
I don't think it is, since reflection only works for Objects, and primitive types aren't objects.

Also the same object can be referenced by many names, and when the program is compiled, the names can easily be stripped since they don't actually matter to the runtime
Page Index Toggle Pages: 1