Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Extract all DownValues that match the input
ResourceFunction["ExtractDownValues"][expr] finds all DownValues that match expr, in the order in which they would be applied by the pattern matcher. | |
ResourceFunction["ExtractDownValues"][head,args] finds all DownValues of head that match head[args]. |
Define a function:
In[1]:= |
Find the DownValues that match abs[23.1]:
In[2]:= |
Out[2]= |
Use the two-argument version to find the DownValues that match abs[c] where c=2+I:
In[3]:= |
Out[3]= |
Find a spoken string:
In[4]:= |
Out[4]= |
Suppose you want to use "where" instead of "slash dot" in this spoken string. Use TracePrint to find the arguments to the internal function SpokenStringDump`SSText used to form the spoken string:
In[5]:= |
Out[5]= |
The internal function used by SpokenString has many DownValues:
In[6]:= |
Out[6]= |
ExtractDownValues can find the first downvalue that matches:
In[7]:= |
Out[7]= |
Modify this downvalue:
In[8]:= |
Check the new output:
In[9]:= |
Out[9]= |
When matching patterns, evaluation leaks can occur. Here is a function that has a side effect:
In[10]:= |
Using ExtractDownValues causes the condition to be evaluated:
In[11]:= |
Out[11]= |
This work is licensed under a Creative Commons Attribution 4.0 International License