MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Extracting the name of a variable

  • To: mathgroup at
  • Subject: [mg26918] Re: [mg26883] Extracting the name of a variable
  • From: Ken Levasseur <Kenneth_Levasseur at>
  • Date: Fri, 26 Jan 2001 23:29:57 -0500 (EST)
  • References: <>
  • Sender: owner-wri-mathgroup at


This seems to work:

z = 3


Attributes[nameExtract] = {HoldAll}


nameExtract[a_] := HoldForm[a] // ToString

nameExtract[z] // FullForm


Ken Levasseur
Math Sci
UMass Lowell

Mike Yukish 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"

  • Prev by Date: Re: metacharacters as record separators
  • Next by Date: Re: [?] apply a function to members of a list
  • Previous by thread: Extracting the name of a variable
  • Next by thread: Re:Extracting the name of a variable