RE: Extracting the name of a variable
- To: mathgroup at smc.vnet.net
- Subject: [mg26929] RE: [mg26883] Extracting the name of a variable
- From: "David Park" <djmp at earthlink.net>
- Date: Fri, 26 Jan 2001 23:30:06 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Mike,
Attributes[nameValue] = HoldFirst;
nameValue[x_] :=
Module[{c = SymbolName[Unevaluated[x]]},
c <> " = " <> ToString[x]]
z = 4;
nameValue[z]
"z = 4"
On the other hand,
?z
Global`z
z = 4
Also
OwnValues[z]
{HoldPattern[z] :> 4}
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
> From: Mike Yukish [mailto:may106 at psu.edu]
To: mathgroup at smc.vnet.net
> Hello,
>
> I'd like to make a function that extracts the name of a variable and
> makes a string. So the function would do:
>
> In: z = 4
>
> In: nameExtract[z]
>
> Out: "z"
>
> It appears to not be so simple, since once you assign z a value, the
> function SymbolName[z] returns an error. what's the trick?
>
> I want to do this so I can make a function takes z as an argument, and
> generates a name:value pair "z=4"
>