[Date Index]
[Thread Index]
[Author Index]
writing a function that would print the name of a passed variable
*To*: mathgroup at smc.vnet.net
*Subject*: [mg97609] writing a function that would print the name of a passed variable
*From*: johnclin at hss.caltech.edu
*Date*: Tue, 17 Mar 2009 04:56:59 -0500 (EST)
I have a question that seems simple but I just could not figure out
how to do it.
I am trying to write a mathematica function that will print the *name*
of the variable that I pass to the function as well as the value
itself.
For example, let's say that I define a variable x = 10.
Now, I want to write a function that will print:
"The variable x contains the value 10".
I tried something like:
displayOutput [varToPrint_] := (
Print["The variable "];
Print[ToString[varToPrint]]; (* <-- this is the problematic line*)
Print["contains the value "];
Print[x];
)
BTW, I do realize that the following works:
x = 10;
Print["The symbol ", HoldForm[x], " has a value of ", x];
So there is something about how Mathematica evaluates expression
inside a function that I am not understanding. Any suggestions?
Prev by Date:
**Re: setting discrete values for a function -- newbie**
Next by Date:
**Re: Re: Using Mathematica notebooks in presentations?**
Previous by thread:
**Re: collecting certain powers**
Next by thread:
**Re: writing a function that would print the name of a**
| |