Function Repository Resource:

DefinedSymbols

Source Notebook

Return a list of strings for all symbols in the given context that have values associated with them

Contributed by: Wolfram|Alpha Math Team

ResourceFunction["DefinedSymbols"][]

returns a list of strings for all symbols in the current context that have values associated with them.

ResourceFunction["DefinedSymbols"][context]

returns a list of strings for all symbols in context that have values associated with them.

Details and Options

ResourceFunction["DefinedSymbols"] checks for symbols in the given context with any OwnValues, DownValues or UpValues.

Examples

Basic Examples (3) 

Clear all global symbols:

In[1]:=
ClearAll["Global`*"];

Set a function to place its head in the global context:

In[2]:=
f[x_] := x^2;

Check that it is now a global symbol:

In[3]:=
ResourceFunction["DefinedSymbols"][]
Out[3]=

Scope (2) 

Clear all global symbols:

In[4]:=
ClearAll["Global`*"];

DefinedSymbols checks for symbols in the global context with any OwnValues, DownValues or UpValues:

In[5]:=
x = 3;
ResourceFunction["DefinedSymbols"][]
Out[5]=

Clear all global symbols:

In[6]:=
ClearAll["Global`*"];

Find a symbol with UpValues:

In[7]:=
g /: h[g[x_]] := x + 1;
ResourceFunction["DefinedSymbols"][]
Out[7]=

Properties and Relations (1) 

DefinedSymbols is more nuanced than simply calling Names to get all symbols in a context:

In[8]:=
ResourceFunction["DefinedSymbols"]["System`"] // Short
Out[9]=
In[10]:=
Names["System`*"] // Short
Out[11]=

Possible Issues (2) 

Remove all global symbols:

In[12]:=
ClearAll["Global`*"];

DefinedSymbols is more subtle than Names:

In[13]:=
h;
Names["Global`*"]
Out[13]=
In[14]:=
ResourceFunction["DefinedSymbols"][]
Out[14]=

Publisher

Wolfram|Alpha Math Team

Version History

  • 2.0.0 – 23 March 2023
  • 1.0.0 – 21 October 2020

Related Resources

Author Notes

To view the full source code for DefinedSymbols, evaluate the following:

In[1]:=
SystemOpen[
 FileNameJoin[{DirectoryName[FindFile["ResourceFunctionHelpers`"]], "DefinedSymbols.wl"}]]

License Information