Re: Extracting the name of a variable
- To: mathgroup at smc.vnet.net
- Subject: [mg26904] Re: Extracting the name of a variable
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Fri, 26 Jan 2001 23:29:47 -0500 (EST)
- References: <94r803$igk@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Mike,
Attributes[ToName] = {HoldFirst};
ToName[x_] := ToString[Unevaluated[x]]
Test:
ToName[z]
"z"
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"Mike Yukish" <may106 at psu.edu> wrote in message
news:94r803$igk 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"
>
>