Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1993

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

Search the Archive

Re: Hold[], Evaluate[] and so forth.

  • To: mathgroup at
  • Subject: Re: Hold[], Evaluate[] and so forth.
  • From: bert at (Roberto Sierra)
  • Date: Wed, 13 Oct 93 11:53:04 -0700

Dear MathGroup, I'm currently in a confused state regarding
the use of Hold[], Evaluate[] etc. Is there a good discussion
of this somewhere (apart from "Mma Book" which is a bit vague).

I've only seen the explanation that appears in the MMA book.
However, by following a lot of the questions and answers that
are posed on the Mathgroup, sci.math.symbolic, and by looking
at various packages to see how Hold[], Unevaluated[], etc., are
used, you can gain quite a bit of insight.

Specifically, I have the following problem: suppose I have a
string containing an expression. I want to get a exact copy
of that as an expression, without any evaluation. I can do:
but this puts a Hold[...] around the result. I can't see any
way of removing the Hold[] without the thing inside getting

That's exactly what Hold[] does -- it *prevents* the inside
from being evaluated.  If you remove the Hold[], then the inside
gets crunched.  How else would you leave something unevaluated?

On a more general level, is there a way to do an Evaluate[]
to some specified level of an expression, rather than
recursing all the way down?

Perhaps the following session will give you some ideas...

(* The held expression *)
expr = ToHeldExpression["2+2+2*2*(2a+2b)+2+2"]
Hold[2 + 2 + 2 2 (2 a + 2 b) + 2 + 2]

(* Only hold expressions at level #3 -- see Map, MapAll, etc. *)
expr1 = ReleaseHold[Map[Hold,expr,{3}]]
8 + Hold[2]  Hold[2 a + 2 b]

(* Only leave multiplications held *)
expr2 = ReleaseHold[
	expr /. Times -> (Hold[Times[##]] &)
8 + Hold[2 2 (Hold[2 a] + Hold[2 b])]

Hope this helps...

 \\|//                         "Television is a medium -- it is
  - -                           neither rare nor well done."
  o o                                            -- Ernie Kovacs
   J   roberto sierra
   O   tempered microdesigns    NOTICE:
  \_/  san francisco, ca        The ideas and opinions expressed
       bert at          herein are not those of the author.

  • Prev by Date: automatic coefficient / summand extraction
  • Next by Date: Student version of Mathematica?
  • Previous by thread: Re: Hold[], Evaluate[] and so forth.
  • Next by thread: Re: Hold[], Evaluate[] and so forth.