Group Abstract Group Abstract

Message Boards Message Boards

0
|
9.5K Views
|
4 Replies
|
9 Total Likes
View groups...
Share
Share this post:

[?] Define a function that operates on patterns?

Posted 7 years ago

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.

POSTED BY: Pavel Perikov
4 Replies

How about Verbatim?

Clear[f];
f[Verbatim[_Real]] := 0;
f[_] := 1;
{f[_Integer] (*1*), f[_Real] (*0*)}
POSTED BY: Gerli Jõgeva
Posted 7 years ago

Exactly! This is THE solution. Thank you!

POSTED BY: Pavel Perikov
POSTED BY: Claudio Chaib
Posted 7 years ago

Thanks! Playing with those now.

POSTED BY: Pavel Perikov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard