Mathematica 9 is now available
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: [mg14660] Re: Protecting from evaluation
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 7 Nov 1998 02:10:12 -0500
  • References: <71q7mm$iu5@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Carl,
I dont get the result that you suggest in the second part of your
message

Clear[li, v, w]

li = {v, w};
v = 20;
w = 25;


heldlist = Thread[HoldForm[li]]

li

Not {HoldForm[v], HoldForm[w]}. Because li is not evaluated.

Hence we get

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

{{20, 25}, {20, 25}}

Not {v,20}

Here are three attempts (all depend on using OwnValues[li]).


Extract[Hold[li] /. OwnValues[li], {1, 1},
  Function[x, {ToString[Unevaluated[x]], x}, HoldFirst]]

{"v", 20}


Extract[Hold[li] /. OwnValues[li], {1, 1},
  Function[x, {HoldForm[x], x}, HoldFirst]]

{v, 20}

{Extract[Hold[li] /. OwnValues[li], {1, 1}, HoldForm ], li[[1]]}

{v, 20}

Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565



Carl Woll wrote in message <71q7mm$iu5 at smc.vnet.net>...
>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: Strange results
  • Next by Date: Re: Abs and derivative problems
  • Previous by thread: Re: Protecting from evaluation
  • Next by thread: Re: Limit, Series and O