Conditional SetDelayed with Replacement
- To: mathgroup at smc.vnet.net
- Subject: [mg92790] Conditional SetDelayed with Replacement
- From: Raffy <raffy at mac.com>
- Date: Mon, 13 Oct 2008 06:20:01 -0400 (EDT)
I've been having difficulty getting the following code to work as
desired.
Clear[f];
Do[f[x_ /; x < i^2] = i, {i, 5}];
The problem should be obvious: the i^2 is not be evaluated (since its
held by SetDelayed).
The only solution I've found thus far, has been doing the following:
Clear[f];
(f[x_ /; x < #^2] = #)& /@ Range[5]
or
Do[(f[x_ /; x < #^2] = #)&[i], {i, 5}];
What kind of Hold, ReleaseHold, Evalulate, or Pattern Replacement
would be needed to get the first example working without using a pure-
function for replacement?