1.15 pattern example 10

Write pattern to select from list [z(1, 1), z(-1, 1), z(-2, 2)] only those with first argument which is negative.

In Maple, we use the form patmatch(X, conditional(patttern,condition))

restart; 
L:=[z(1, 1), z(-1, 1), z(-2, 2)]; 
map( proc(X) local la,a,b; 
     if patmatch(X, conditional(z(a::integer,b::integer),a<0),'la') then 
        z(eval(a,la),eval(b,la)); 
     else 
        NULL; 
     fi; 
     end proc, L 
    ); 
 
 
         [z(-1, 1), z(-2, 2)]
 

In Mathematica

Cases[{z[1, 1], z[-1, 1], z[-2, 2]}, z[x_ /; x < 0, y_]] 
 
    {z[-1,1],z[-2,2]}