Condition vs PatternTest
- To: mathgroup at smc.vnet.net
- Subject: [mg42081] Condition vs PatternTest
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Wed, 18 Jun 2003 02:11:06 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I wonder if people can help me understand the difference between
(pattn?test) and (pattn/;test).
I understand when each form is normally used, but I want to understand what
is happening under the hood.
Typical usage of (pattn?test) and (pattn/;test) are given in f1 and f2
below.
Clear[f1,f2]
f1[x_?Positive] := x+1
f2[x_,y_]/;x<y := x+y
However, we can define g1, g2 below which give the same result as f1, f2
respectively. Notice how the test in (g2) must carfully prevent evaluation.
Clear[g1,g2]
g1[x_/;Positive[x]]:=x+1
g2[x_,y_]?(Function[a,Part[Unevaluated[a],1]<Part[Unevaluated[a],2],{HoldAll
}]):=x+y
Can somebody explain how evaluation of (pattn?test) differs from evaluation
of (pattn/;test).
-----------
Thanks,
Ted Ersek
Get Mathematica tips, tricks from
http://www.verbeia.com/mathematica/tips/Tricks.html