Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Protecting from evaluation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg14622] Re: [mg14588] Protecting from evaluation
  • From: Carl Woll <carlw at fermi.phys.washington.edu>
  • Date: Wed, 4 Nov 1998 13:46:51 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Hi William,

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

v=20;
ToString[v]

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

ClearAll[HoldToString]
SetAttributes[HoldToString, {HoldAll}] HoldToString[x_] :=
ToString[Unevaluated[x]]

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

HoldForm[v]

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

{HoldForm[v],v}

will return

{v,20}

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

li = {v,w}

and then you set

v=20;
w=25;

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

heldlist=Thread[HoldForm[li]];

which will have the FullForm

List[HoldForm[v],HoldForm[w]]

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]
> 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