MathGroup Archive 1998

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

Search the Archive

Re: Protecting from evaluation

  • To: mathgroup at
  • Subject: [mg14622] Re: [mg14588] Protecting from evaluation
  • From: Carl Woll <carlw at>
  • Date: Wed, 4 Nov 1998 13:46:51 -0500
  • Sender: owner-wri-mathgroup at

Hi William,

The problem with your first function is that ToString evaluates its
argument before turning it into a string. Thus, if


will return 20. If you really want to use ToString in this way, it is
better to create your own function, as in

SetAttributes[HoldToString, {HoldAll}] HoldToString[x_] :=

However, what is wrong with the function HoldForm? For example,


will display v, while it's FullForm is still HoldForm[v]. Thus,


will return


For the second part of your question, say you have a list

li = {v,w}

and then you set


If I understand your question, you want to be able to display the
unevaluated form of the first element of li. One idea is to use
HoldForm again, as in


which will have the FullForm


Then, if you want to print v and the value of v, you could do

{heldlist[[1]], ReleaseHold[heldlist[[1]]]}

or some suitable variant.

Carl Woll
Dept of Physics
U of Washington

On Mon, 2 Nov 1998, William B. Marks wrote:

> To display variable names along with their values I can put them in
> quotes first using
> quote[var_] := ToString[var]
> SetAttributes[quote,HoldAllComplete].
> Then this works
> quote[Unevaluated @ cVWGL]
> but this fails
> quote[cVWGL]
> 20
> but since this fails
> Unevaluated /@ {cVThGL, cVWGL}
> {Unevaluated[900], Unevaluated[20.]}
> I can't see a way to protect members of a list of variables except by
> putting quotes around them by hand. Any suggestions?

  • Prev by Date: Re: Options using Print
  • Next by Date: Re: Abs and derivative problems
  • Previous by thread: Protecting from evaluation
  • Next by thread: Re: Protecting from evaluation