Re: Reevaluation of conditional arguments when the condition has changed

*To*: mathgroup at smc.vnet.net*Subject*: [mg61083] Re: [mg61046] Reevaluation of conditional arguments when the condition has changed*From*: Igor Antonio <igora at wolf-ram.com>*Date*: Sun, 9 Oct 2005 01:36:31 -0400 (EDT)*Organization*: Wolfram Research, Inc.*References*: <200510080649.CAA20991@smc.vnet.net>*Reply-to*: igora at wolf-ram.com*Sender*: owner-wri-mathgroup at wolfram.com

David Park wrote: > Dear MathGroup, > > Here is a programming problem that stumps me. We start with a condition that is always False. > > fooQ[_] := False > > Then write a definition that will factor out multipliers of fooQ objects. > > foo[a_ b_?fooQ] := a foo[b] > > The following does not factor because b, or anything else, fails the test. > > expr1 = foo[a b] > giving: foo[a b] > > Now I define b as a fooQ object. > > fooQ[b] := True > > Now when I enter the same expression the a factors out. > > foo[a b] > giving: a foo[b] > > But if I reevaluate expr1 the definition is not applied. > > expr1 > giving: foo[a b] > > Why shouldn't I expect that to evaluate and now factor? Is there a proper way to write the definitions so it will evaluate? > > David Park > djmp at earthlink.net > http://home.earthlink.net/~djmp/ > David, You shouldn't expect it because you're using the Set function (=). When you call: expr1 = foo[a b] It evaluates the rhs (giving "foo[a b]") and sets that *value* to the value of expr1. Note it's *not* the function definition foo[a b], but it's value. Its value just happened to be the "unevaluated value", but it's still its value. When you modify the foo function and reevaluate expr1 (I'm assuming you're simply doing "expr1" in a new cell), you're simply getting that value that was stored in the variable. That is the whole idea behind using Set vs. SetDelayed ( := ) If you had used: expr1 := foo[a b] then the contents of expr1 would be the actual function definition of foo and it would be reevaluated when you evaluated expr1, giving you the result you desire. -- Igor C. Antonio Wolfram Research, Inc. http://www.wolfram.com To email me personally, remove the dash.

**References**:**Reevaluation of conditional arguments when the condition has changed***From:*"David Park" <djmp@earthlink.net>