MathGroup Archive 2010

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

Search the Archive

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

  • To: mathgroup at
  • Subject: [mg109573] Re: Return intermediate reference using Hold*****?
  • From: Bob Hanlon <hanlonr at>
  • Date: Thu, 6 May 2010 04:50:37 -0400 (EDT)


SetAttributes[matchType, HoldFirst]

  candidates_?(VectorQ[#, StringQ] &)] :=
  {typeStr = SymbolName[Unevaluated[type]]},
   DeleteCases[candidates, typeStr],
   ToExpression[# <> "==" <> typeStr] &]]

GrassA = 1;

GrassB = 2;

GrassC = 2;

This last entry could either be an error or a form of naming conflict caused by using capital letters at the start of user-defined names.

GrassType = GrassA;

matchType[GrassType, {"GrassA", "GrassB"}]


Or to drop the list brackets

matchType[GrassType, {"GrassA", "GrassB"}][[1]]


matchType[GrassType, Names["Grass*"]]


GrassType = GrassB;

matchType[GrassType, {"GrassA", "GrassB"}]


matchType[GrassType, Names["Grass*"]]


This last example detects the ambiguity or name similarity. This is why it is best (my opinion) to drop the list brackets outside the function rather than inside.

Bob Hanlon

---- Adam <juneappal 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

(*Lots of code and calculations, followed by summary printout *)

Print[Row[{"GrassType = ", HOLDLIKEFUNCTION[GrassType], "\tDepth = ",

HoldForm[GrassType] returns "GrassType," instead of the desired

For now, I am using:
Clear[GrassA, GrassB]
Print[Row[{"GrassType = ", HOLDLIKEFUNCTION[GrassType], "\tDepth = ",

Which has the desired effect, so I am not desparate for a solution -
just wonder how other people would approach this.

  • Prev by Date: Re: ComplexExpand and subscrips
  • Next by Date: Re: mathlink error handling inside :Begin: - :End:
  • Previous by thread: Re: Return intermediate reference using Hold*****?
  • Next by thread: Re: Return intermediate reference using Hold*****?