[?] Define a function that operates on patterns?

Hello everybody.

I’m trying to define a function that accepts a pattern as a parameter. After playing with HoldPattern and HoldAll attributes I’m out of ideas.

Is this at all possible? Here’s an example of what I’d like to get:

Remove[f];
f[HoldPattern[Blank[Real]]] := 0; 
f[a_] := 1; SetAttributes[f, HoldFirst];
f[_Real] (* expecting to get 0 *)

Pure function will receive a pattern as expected.

Any ideas are welcome.

Hi Pavel, see if any of these examples are useful for you:

Clear[f];
a := {f[a_] := 1};
f[HoldPattern[_]] := 0;

f[_Real]
a;
f[_Real]

8405i1.png

Clear[f];
f[a_] := a /. x_ /; x === pat -> 0;

f[pat]
f[3]
f[1]

6961i2.png

Clear[f];
f[a_: 10] := a;

f[]
f[2]
f[3]

5324i3.png

Clear[f];
f[a_] := a /. {pat -> 0, _ -> 1};

f[pat]
f[2]
f[3]

5785i4.png

Clear[f];
f[a_] := If[a \[Element] NegativeIntegers, 0, a];

f[2]
f[-2]
f[2.37]

4341i5.png

How about Verbatim?

Clear[f];
f[Verbatim[_Real]] := 0;
f[_] := 1;
{f[_Integer] (*1*), f[_Real] (*0*)}

Thanks! Playing with those now.

Exactly! This is THE solution. Thank you!