MathGroup Archive 2010

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

Search the Archive

Re: Return intermediate reference using Hold*****?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109592] Re: Return intermediate reference using Hold*****?
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Fri, 7 May 2010 06:29:12 -0400 (EDT)

Hi Adam,

If you are willing to replace the Set with SetDelayed in the definition of
GrassType (which you said you
want to change from operation to operation), then there is a fairly simple
solution:

In[6]:=
GrassA = 1
GrassB = 2

Out[6]= 1

Out[7]= 2

In[8]:= GrassType := GrassA

And this is all you need to do:

In[9]:= Hold[GrassType] /. OwnValues[GrassType]

Out[9]= Hold[GrassA]

You can of course use HoldForm instead of Hold, or generally any head with
some Hold* attribute. If you want to convert to string, use something like
ToString[HoldForm[GrassType] /. OwnValues[GrassType]].

Hope this helps.

Regards,
Leonid


On Tue, May 4, 2010 at 2:29 PM, Adam <juneappal at gmail.com> wrote:

> Hello -
>
> Supposing I have declared:
> x = 1
> y = x
>
> Is there a function that can take y as an argument and return  "x"?
>
> I would like to use it like this:
>
>
> ***
> GrassA = 1
> GrassB = 2
> GrassType = GrassA  (*<---- I will toggle this for different model
> runs*)
>
> (*Lots of code and calculations, followed by summary printout *)
>
> Print[Row[{"GrassType = ", HOLDLIKEFUNCTION[GrassType], "\tDepth = ",
> h}]]
>
>
> *****
> HoldForm[GrassType] returns "GrassType," instead of the desired
> "GrassA."
>
> For now, I am using:
> ******
> Clear[GrassA, GrassB]
> Print[Row[{"GrassType = ", HOLDLIKEFUNCTION[GrassType], "\tDepth = ",
> h}]]
> ******
>
> Which has the desired effect, so I am not desparate for a solution -
> just wonder how other people would approach this.
>
>
>
>



  • Prev by Date: Plot3D problems: no plot in some cases
  • Next by Date: 2D phase unwrapping
  • Previous by thread: Re: Return intermediate reference using Hold*****?
  • Next by thread: Table of Values