Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Pick named elements of a pattern
ResourceFunction["PatternBindings"][expr,pattern] gives a list of elements of expr matching named parts of pattern. |
Find parts of an expression that match the named elements of a pattern:
| In[1]:= |
| Out[1]= |
Test if an expression matches the pattern:
| In[2]:= |
| Out[2]= |
PatternBindings can be useful for debugging and code analysis:
| In[3]:= |
| In[4]:= |
| Out[4]= |
PatternBindings returns a failure object in cases for which MatchQ returns False:
| In[5]:= |
| Out[5]= |
| In[6]:= |
| Out[6]= |
PatternBindings uses the standard rules when resolving ambiguity:
| In[7]:= |
| Out[7]= |
Compare, for instance, with pattern matching in a function definition:
| In[8]:= |
| In[9]:= |
| Out[9]= |
PatternBindings picks up only named elements in patterns:
| In[10]:= |
| Out[10]= |
ReplaceAll can be used instead of PatternBindings:
| In[11]:= |
| Out[11]= |
| In[12]:= |
| Out[12]= |
PatternBindings does not find elements taken verbatim:
| In[13]:= |
| Out[13]= |
This work is licensed under a Creative Commons Attribution 4.0 International License