Re: Evaluate part of rhs of RuleDelayed

• To: mathgroup at smc.vnet.net
• Subject: [mg91095] Re: Evaluate part of rhs of RuleDelayed
• From: David Bailey <dave at Remove_Thisdbailey.co.uk>
• Date: Wed, 6 Aug 2008 05:04:14 -0400 (EDT)
• 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[5] 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[5] be {value :> SomeComplexFunction[30]} ?
>
> Unfortunately, this one
>
> SomeComplexFunction[a_] := Module[{x},
>   x = a*a;
>   {value :> SomeComplexFunction[Evaluate[x + a]]}]
>
> yields {value :> SomeComplexFunction[Evaluate[x\$7421 + 5]]}
>

The With function is extremely useful for injecting values inside code
that does not immediately evaluate:

SomeComplexFunction[a_]:=Module[{x},
x=a*a;
With[{xx=x+a},{value:>SomeComplexFunction[xx]}]
]

David Bailey
http://www.dbaileyconsultancy.co.uk

```

• Prev by Date: Re: GPU vs CPU in Mathematica 6
• Next by Date: Re: Package conversion to V6
• Previous by thread: Re: Evaluate part of rhs of RuleDelayed
• Next by thread: Re: Evaluate part of rhs of RuleDelayed