Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: Releasing several Holds simultaneously

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82311] Re: Releasing several Holds simultaneously
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Wed, 17 Oct 2007 04:06:51 -0400 (EDT)
  • References: <ff1po5$90n$1@smc.vnet.net>

Hi,

I love such questions ! Try:

RemoveInnerHold[expr_] :=
  Module[{syms, rep, nexpr},
   syms = Cases[expr,
     Except[Hold | HoldComplete | HoldPattern | HoldForm, _Symbol],
     Infinity, Heads -> True];

   rep = Thread[syms -> Table[Unique[], {Length[syms]}]];
   nexpr = (expr /. rep) //. Hold[any_] :> any;
   nexpr /. (Reverse /@ rep)
   ]

while
Hold[Hold[q] + Hold[c] + Hold[2 + 3 + 4]] // ReleaseHold
gives
Hold[2 + 3 + 4] + Hold[c] + Hold[q]

but

RemoveInnerHold[Hold[Hold[q] + Hold[c] + Hold[2 + 3 + 4]]]

gives

9+c+q

Regards
   Jens


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.
> 
> % /. Hold[x_]:>x does the same thing, because /. only matches once per part.
> 
> 


  • Prev by Date: Re: Transparently passing on options to other functions
  • Next by Date: Re: Help with NMinimize
  • Previous by thread: RE: Releasing several Holds simultaneously
  • Next by thread: Re: Releasing several Holds simultaneously