Re: Putting an expression into a module
- To: mathgroup at smc.vnet.net
- Subject: [mg84892] Re: Putting an expression into a module
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Fri, 18 Jan 2008 05:47:19 -0500 (EST)
- References: <fmngh8$3fl$1@smc.vnet.net>
Hugh wrote:
> Suppose you have generated a long symbolic expression, e, and now wish
> to use the expression inside a Module. One method would be to cut-and-
> paste the expression into the Module but how do you do this without
> cutting-and-pasting?
> Below in a warm up problem I first get what I want by cutting-and-
> pasting and then try various combinations of Hold, ReleaseHold and
> Evaluate. These don't work (why?) but how can it be done?
>
> Thanks
> Hugh Goyder
>
> e = y^2 - x^2
>
> ClearAll[f];
> ReleaseHold[f[x_] := Hold[Module[{y}, y /. FindRoot[e1, {y, 1}]]] /.
> e1 -> e]
>
Hi,
Wrap the complete assignment in Hold, like this:
ReleaseHold[Hold[f[x_] := Module[{y}, y /. FindRoot[e1, {y, 1}]]] /. e1
-> e]
--
Szabolcs