RE: Releasing several Holds simultaneously

• To: mathgroup at smc.vnet.net
• Subject: [mg82329] RE: Releasing several Holds simultaneously
• From: "Andrew Moylan" <andrew.j.moylan at gmail.com>
• Date: Wed, 17 Oct 2007 04:16:11 -0400 (EDT)
• References: <ff1po5\$90n\$1@smc.vnet.net> <47147224.60309@gmail.com>

```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.

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;

Andrew

-----Original Message-----
From: Szabolcs Horv=E1t [mailto:szhorvat at gmail.com]
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
Unevaluated[].

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

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

--
Szabolcs

```

• 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