See PatternTest.
x_?test matches if test[x] is True. It is equivalent to x_ /; test[x] (see Condition).
x_symbol matches if Head[x] is symbol.
m_?Integer makes no sense because Integer is not a function that returns True or False. m_?IntegerQ is valid and works. See Integer and IntegerQ.
_Integer and _?IntegerQ are very similar, but there are some important differences:
_Integer is faster than _?IntegerQ:
list = Developer`FromPackedArray@RandomInteger[1000, 1000000];
fun1[_Integer] := "x";
fun2[_?IntegerQ] := "x";
fun1 /@ list; // Timing
(* {0.23702, Null} *)
fun2 /@ list; // Timing
(* {0.376331, Null} *)
But _Integer also matches expressions which are not really integers, such as Integer["abc"].
The same applies to other, similarly named functions as well.
_?GraphQ and _Graph are not the same. _?AssociationQ and _Association are not the same. This is because there are expressions with the head Association that are not atomic associations.
expr = Association[123]
(* Association[123] *)
MatchQ[expr, _Association]
(* True *)
MatchQ[expr, _?AssociationQ]
(* False *)
In these cases, one usually needs the pattern _?AssociationQ. Then the expression will work with functions like Lookup, KeyTake, etc.
There is even use for _Association?AssociationQ. This pattern is faster to reject non-associations than _?AssociationQ, but it is otherwise functionally equivalent.
expr /. {x^m_?IntegerQ :> x^Mod[m, 2]}– kglr May 12 '19 at 10:01https://mathematica.stackexchange.com/questions/9356/assessing-argument-type-in-set-delayed-function-definitions
– Mark Robinson May 12 '19 at 10:25_?funcpattern thenfunccan be any function at all. Any function you can think of._headis a shorthand for the patternhead[___]. A pattern that doesn't involve arbitrary black box functions can be optimized in ways that it couldn't if it had to evaluate arbitrary functions on each possible match. Don't use_?funcunless you have to. – C. E. May 12 '19 at 10:51m_?Integeris incorrect. Did you meanIntegerQ? – Szabolcs May 12 '19 at 11:05