Re: Return intermediate reference using Hold*****?
- To: mathgroup at smc.vnet.net
- Subject: [mg109564] Re: Return intermediate reference using Hold*****?
- From: Rui <rui.rojo at gmail.com>
- Date: Wed, 5 May 2010 06:06:56 -0400 (EDT)
- References: <hrosu4$5qb$1@smc.vnet.net>
On May 4, 7:29 am, Adam <juneap... 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.
Not sure I understood the issue.
If you do this:
GrassA=1;
GrassType=GrassA;
GrassType is stored as 1, the symbol "GrassA" is not associated to
GrassType
If you do this:
GrassType:=GrassA;
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";
GrassValue["GrassA"]=1;
..
or as symbols, as upvalues, or not
If I didn't get it, please reexplain your issue