|
[Date Index]
[Thread Index]
[Author Index]
Re: Reevaluation of conditional arguments when the condition has changed
- To: mathgroup at smc.vnet.net
- Subject: [mg61084] Re: [mg61046] Reevaluation of conditional arguments when the condition has changed
- From: Carl Woll <carlw at wolfram.com>
- Date: Sun, 9 Oct 2005 01:36:35 -0400 (EDT)
- References: <200510080649.CAA20991@smc.vnet.net>
- 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/
>
Hi David,
Take a look at the documentation for Update:
"Update[symbol] tells Mathematica that hidden changes have been made
which could affect values associated with a symbol. Update[ ] specifies
that the value of any symbol could be affected." More?
One of the notes on the Update function page also states:
"One special circumstance is that changes in the value of one symbol can
affect the value of another symbol by changing the outcome of Condition
tests. In such cases, you may need to use Update on the symbol you think
may be affected."
So, to correct your problem, simply update foo:
Update[foo]
and then retry evaluating expr1.
Carl Woll
Wolfram Research
Prev by Date:
Re: Reevaluation of conditional arguments when the condition has changed
Next by Date:
Re: a very simple graphics problem
Previous by thread:
Re: Reevaluation of conditional arguments when the condition has changed
Next by thread:
Re: Reevaluation of conditional arguments when the condition has changed
|