It's a problem with the precedence of operators. You need a set of parentheses to specify that the [0] part is to apply to GreaterThan instead of to the whole PatternTest expression:
Clear[f]
f[a_?(GreaterThan[0])] := "!"
f[6] (* ! *)
You can see the difference in FullForm:
FullForm[a_?GreaterThan[0]] (* no parentheses *)
FullForm[a_?(GreaterThan[0])] (* with parentheses *)
returns:
PatternTest[Pattern[a, Blank[]], GreaterThan][0] (* no parentheses *)
PatternTest[Pattern[a, Blank[]], GreaterThan[0]] (* with parentheses *)
? has very high precedence, in particular higher than [] (see this Operator precedence table)
.
f[a_?(#>0&)]:="!"; also checkGreaterandPatternTest(hint: whatever follows the?must return a boolean value) – yosimitsu kodanuri Jul 05 '18 at 15:23GreaterThan. Then the lack of a parenthesis is revealed. I.e.f[a_?(GreaterThan[0])] := "!"– Coolwater Jul 05 '18 at 16:14?is an incredibly high precedence operator (even more so that[...]. It binds theGreaterThaninstead ofGreaterThan[0]. – b3m2a1 Jul 05 '18 at 16:17