       Re: Evaluate part of rhs of RuleDelayed

• To: mathgroup at smc.vnet.net
• Subject: [mg91123] Re: Evaluate part of rhs of RuleDelayed
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Wed, 6 Aug 2008 05:09:35 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <g79a05\$dnl\$1@smc.vnet.net>

```Eugene Kirpichov wrote:

> I am writing a lazy recursive function (actually, a tree of UI widgets
> that is too large to be constructed at once).
> Consider, for example, the following code:
>
> SomeComplexFunction[a_] := Module[{x},
>   x = a*a;
>   {value :> SomeComplexFunction[x + a]}]
>
> The value of SomeComplexFunction is {value :>
> SomeComplexFunction[x\$7418 + 5]} and seemingly can'd be used for
> anything useful.
>
> Question:
> How should I fix the code of SomeComplexFunction so that the value of
> SomeComplexFunction be {value :> SomeComplexFunction} ?
>
> Unfortunately, this one
>
> SomeComplexFunction[a_] := Module[{x},
>   x = a*a;
>   {value :> SomeComplexFunction[Evaluate[x + a]]}]
>
> yields {value :> SomeComplexFunction[Evaluate[x\$7421 + 5]]}

What you want to do is evaluating the argument of a function without
evaluating the function itself (You use RuleDelayed to prevent the
evaluation of the function and the infinite loop that would result in
doing so).

You can use ReplacePart to modify selectively any parts of the rule, so
you can replace the unevaluated argument by its result. (Note that the
right sequence of indices can be found by using FullForm or TreeForm,
for instance.)

SomeComplexFunction[a_] :=
Module[{x}, x = a*a;
ReplacePart[{value :> SomeComplexFunction[x + a]},
{1, 2, 1} -> x + a]]

SomeComplexFunction

{value :> SomeComplexFunction}

Regards,
-- Jean-Marc

```

• Prev by Date: Re: Can not run Mathematica 6.0.3 on Fedora 9
• Next by Date: Re: Incoherent value for partial derivative
• Previous by thread: Re: Evaluate part of rhs of RuleDelayed
• Next by thread: Find count of binary number pattern within concatenated number