Function Repository Resource:

SymbolCases

Source Notebook

Find symbols whose definition contains specified pattern

Contributed by: Taliesin Beynon

ResourceFunction["SymbolCases"]["context",patt]

finds all symbols in context which have a definition that contains patt at any level.

Details and Options

ResourceFunction["SymbolCases"] returns names of the symbols it finds.
ResourceFunction["SymbolCases"] checks definitions given as DownValues, OwnValues, UpValues, SubValues and FormatValues.

Examples

Basic Examples (3) 

Define a simple package:

In[1]:=
BeginPackage["checkValue`"];
checkInteger[_Integer] := "integer";
checkReal[_Real] := "real"
EndPackage[]

Find symbols in the package whose definition contains the specified word:

In[2]:=
ResourceFunction["SymbolCases"]["checkValue`", "integer"]
Out[2]=

The result is a list of strings:

In[3]:=
% // InputForm
Out[3]=

Scope (2) 

Define a package that sets DownValues, OwnValues, UpValues, SubValues and FormatValues of symbols:

In[4]:=
BeginPackage["values`"];
downValues[_] := 1;
ownValues := 2;
upValues /: f[upValues[_]] := 3;
subValues[_][_] := 4;
formatValues[_, _] := Null;
Format[formatValues[_?(# < 5 &)]] := "formatted";
EndPackage[]

Find package symbols that have integers in their definitions:

In[5]:=
ResourceFunction["SymbolCases"]["values`", _Integer]
Out[5]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 16 January 2019

License Information