Wolfram Computation Meets Knowledge

SymbolCases

Contributed by: Taliesin Beynon

Find symbols whose definition contains specified pattern

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

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

Details and Options

SymbolCases returns names of the symbols it finds.
SymbolCases checks definions given as DownValues,OwnValues,UpValues, SubValues, and FormatValues.

Examples

Basic Examples

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

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]=

Resource History