Re: SymbolName question
- To: mathgroup at smc.vnet.net
- Subject: [mg61811] Re: [mg61794] SymbolName question
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Mon, 31 Oct 2005 01:17:05 -0500 (EST)
- Reply-to: hanlonr at cox.net
- Sender: owner-wri-mathgroup at wolfram.com
x=5; SymbolName[Unevaluated[x]] "x" SetAttributes[mySymbolName,HoldAll]; mySymbolName[x_Symbol]:=SymbolName[Unevaluated[x]]; mySymbolName[x] "x" Bob Hanlon > > From: "Matt" <anonmous69 at netscape.net> To: mathgroup at smc.vnet.net > Date: 2005/10/30 Sun AM 12:43:23 EDT > Subject: [mg61811] [mg61794] SymbolName question > > Hello, > It seems that if I want to print the 'name' of a symbol, that I need > to save it in a variable before I actually use it. Is this expected > behaviour? It would be imminently more useful if I could give any > symbol to SymbolName and it would give me a string representation of > the variable name. > e.g. > > a1Name = SymbolName[a1]; > a1 = Array[r, {2, 2, 2}]; > Print["The symbol ", a1Name, " has a value of ", a1]; > > works, but if I try this: > > a1 = Array[r, {2, 2, 2}]; > Print["The symbol ", SymbolName[a1], " has a value of ", a1]; > > it doesn't, and I get the following error: > SymbolName::sym : Argument {nested list} at position 1 is expected to > be a symbol. More... > > The online help states the following: > "Once you have made an assignment such as x = 2, then whenever x is > evaluated, it is replaced by 2. Sometimes, however, you may want to > continue to refer to x itself, without immediately getting the value of > x. > > You can do this by referring to x by name. The name of the symbol x is > the string "x", and even though x itself may be replaced by a value, > the string "x" will always stay the same." > > This seems to indicate that what I want to accomplish should in fact > work without the need to first save the string representation of a > symbol name before any value is assigned to it. > > $Version > 5.1 for Microsoft Windows (October 25, 2004) > > Thanks, > > Matt > >