Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

Re: Extracting the name of a variable

  • To: mathgroup at smc.vnet.net
  • Subject: [mg26963] Re: Extracting the name of a variable
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Tue, 30 Jan 2001 03:38:16 -0500 (EST)
  • References: <94tl4s$lck@smc.vnet.net> <94vrdo$o8i@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Mike,
> So passing a predeclared list is a different story, and Ted pointed that
out. I
> think I can live with the restriction, though.

Here's a way to get round the restriction - the ideas are more generally
applicable.

list1 := {q, z, w};

q = {1, 2, 3};

Attributes[ExtractNames] = {HoldAll};

ExtractNames[x_] := ReleaseHold[
    Map[ToString[Unevaluated[#]] &, Hold[x] /. OwnValues[x], {2}]
    ]

ExtractNames[x_] := ReleaseHold[
    Map[
      Function[t, ToString[Unevaluated[t]], HoldAll],
      Hold[x] /. OwnValues[x], {2}]
    ]

ExtractNames[list1]

{"q", "z", "w"}

--
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:94vrdo$o8i at smc.vnet.net...
> "Ersek, Ted R" wrote:
>
> > Mike Yukish asked how one can take a variable which has a value assigned
and
> > convert it to a string without letting it evaluate.
> >
> > I provide the solution in the section for (ToString) on my web site.
The
> > URL is
> > http://www.verbeia.com/mathematica/tips/Tricks.html
>
> Many thanks to all who replied. I posed my problem as a subpart of a more
> complex problem, which still defeats me. I had hoped to Map[ ] the
function
> extractName over a list, and extract the names of all the variables in the
list.
> Ted has identified its difficulties, which I offer up here.
>
> Problem: Create a function that takes a list of variables, and extracts
the
> symbol name of each. This is an added level over the initial problem.
>
> q=4
> z=5
>
> list1={q,z,w}
>
> extractNamesFromList[list1]
>
> out[]:=
>
> {"q","z","w"}
>
> Ted Ersek and Bob Hanlon have both shown me how to create a function that
will
> work with
>
> extractNamesFromList[{q,z,w}]
>
> out[]:=
> {"q","z","w"}
>
>
> but  extractNamesFromList[list1]
> out[]:=
> "list1"
>
> So passing a predeclared list is a different story, and Ted pointed that
out. I
> think I can live with the restriction, though.
>
>
>
>




  • Prev by Date: RE: 1. Input of screen coordinates; 2. Fast graphics
  • Next by Date: Re: Multiply 2 Lists together in a certain way
  • Previous by thread: Re: Re: Extracting the name of a variable
  • Next by thread: Napoleon