MathGroup Archive 2010

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

Search the Archive

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

  • To: mathgroup at
  • Subject: [mg109564] Re: Return intermediate reference using Hold*****?
  • From: Rui <rui.rojo at>
  • Date: Wed, 5 May 2010 06:06:56 -0400 (EDT)
  • References: <hrosu4$5qb$>

On May 4, 7:29 am, Adam <juneap... at> 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.

Not sure I understood the issue.
If you do this:
GrassType is stored as 1, the symbol "GrassA" is not associated to

If you do this:
then you store it as GrassA. However, whereeeever you decide to
evaluate GrassType,
Mathematica will ineeeevitably evaluate the resulting expression again
and again until it doesn't change (or the max numbers of iterations is
reached. Forget about that). So, if you ever wanted to evaluate
GrassType in a way that it returns the symbol GrassA/GrassB, then you
should make sure they don't evaluate to anything, e.g, putting them in
a block.
If your objective is simply to associate a grasstype and then be able
to fetch, somehow, the type name and/or the current value assigned to
it, there are plenty of neater ways to do so, such as
GrassType="GrassA"; (*or*) GrassType[myGarden]="GrassA";
or as symbols, as upvalues, or not

If I didn't get it, please reexplain your issue

  • Prev by Date: Parallelize NonlinearModelFit
  • Next by Date: Re: Definition of Deploy
  • Previous by thread: Return intermediate reference using Hold*****?
  • Next by thread: Re: Return intermediate reference using Hold*****?