This question arised after reading the almost-last example appearing in the technote on Patterns, in section Putting Constraints on Patterns.
Why the following function doesn't work?
q[x_Integer, y_Integer?(Function[{v, u}, v + u < 8])] := qp[x + y]
That is, I want the function q
to be evaluated only if x+y<8
, by using a pure function, so that, for example,
{q[{3, 4}], q[{1, 1}], q[{-5, -7}]}
would return
(*{qp[7],qp[2],q[{-5,-7}]}*)
Note that the following works:
q[{x_Integer, y_Integer}?(Function[v, v[[1]] + v[[2]] < 8])] := qp[x + y]
But I want the function q
to accept two separate arguments x
and y
, and not a list of two arguments {x,y}
.