MathGroup Archive 2007

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

Search the Archive

RE: Releasing several Holds simultaneously

Hi Szabolcs,

My general expression is of the form Hold[SetDelayed[a, b]] where both a and
b may contain one or more Holds. The expression is the result of using
Mathematica to generate Mathematica code.

I start with Hold[SetDelayed[a, b]] and then insert (via /. and
placeholders) code into b. The reason b contains Holds is that some of the
pieces of code that I insert into it are wrapped in Hold because they can't
be evaluated:

pieceofcode = Hold[z[[1]]];

So I could generalise my question like this:

Suppose I have Hold[a := b] and I have pieceofcode = Hold[z[[1]]]. How can I
arrange to evaluate a := z[[1]]?

Here's my present solution:

SetAttributes[SuperHold, HoldAll];
ReleaseSuperHold[expr_] := expr /. SuperHold[x_] :> x;

pieceofcode = Hold[z[[1]]];
SuperHold[a := b] /. b -> pieceofcode //
  ReleaseHold // ReleaseSuperHold;


-----Original Message-----
From: Szabolcs Horv=E1t [mailto:szhorvat at]
Sent: Tuesday, 16 October 2007 6:11 PM
To: Andrew Moylan
Subject: [mg82329] Re: Releasing several Holds simultaneously

Andrew Moylan wrote:
> Hold[a := Hold[1]]
> How can I release both of these Holds (and thus execute a:=1)
> simultaneously?
> ReleaseHold[%] doesn't work; it evaluates a := Hold[1] before the
> other hold is removed.

Hi Andrew,

How did you construct the expression Hold[a := Hold[1]]?  Perhaps there is a
way to avoid the double Hold and construct Hold[a := 1] directly (even if
there is an expression in place of '1' that must not be evaluated), using

> % /. Hold[x_]:>x does the same thing, because /. only matches once per

If you use Replace instead of ReplaceAll, then you can specify the level at
which the replacement should be done.

Replace[Hold[a := Hold[1]], Hold[x_] -> x, {2}]


  • Prev by Date: Re: Is this normal for Limit?
  • Next by Date: Re: Integrate question
  • Previous by thread: RE: Releasing several Holds simultaneously
  • Next by thread: Re: Releasing several Holds simultaneously