Re: Extracting the name of a variable
- To: mathgroup at smc.vnet.net
- Subject: [mg26895] Re: [mg26883] Extracting the name of a variable
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Fri, 26 Jan 2001 23:29:42 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Presumably you mean something like this: In[1]:= SetAttributes[ExtractNameAndValue, HoldFirst] In[2]:= ExtractNameAndValue[z_Symbol] := With[{u = z}, SymbolName[Unevaluated[z]] <> "=" <> ToString[u]] In[3]:= z = 5; In[4]:= ExtractNameAndValue[z] Out[4]= "z=5" ? -- Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ http://sigma.tuins.ac.jp/ on 01.1.26 3:27 PM, Mike Yukish at may106 at psu.edu wrote: > 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" > > >