Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Get all the non-local symbols that appear in an expression
ResourceFunction["GetUnboundSymbols"][expr] gets all the non-local symbols that appear in expr. | |
ResourceFunction["GetUnboundSymbols"][expr,wrapper] wraps each symbol in wrapper before returning the result. |
Get the unbound symbols in an expression:
In[1]:= |
![]() |
Out[1]= |
![]() |
Supply a head to be applied to each symbol:
In[2]:= |
![]() |
Out[2]= |
![]() |
Use Unevaluated and a wrapper such as Hold to prevent evaluation:
In[3]:= |
![]() |
Out[3]= |
![]() |
In[4]:= |
![]() |
Out[4]= |
![]() |
Ignore symbols that are locally bound by Function:
In[5]:= |
![]() |
Out[5]= |
![]() |
GetUnboundSymbols ignores symbols bound by scoping constructs such as Block, With and Module:
In[6]:= |
![]() |
Out[6]= |
![]() |
In[7]:= |
![]() |
Out[7]= |
![]() |
In[8]:= |
![]() |
Out[8]= |
![]() |
RuleDelayed has local bindings:
In[9]:= |
![]() |
Out[9]= |
![]() |
SetDelayed also has local bindings:
In[10]:= |
![]() |
Out[10]= |
![]() |
The x on the right-hand side of the Set is unbound:
In[11]:= |
![]() |
Out[11]= |
![]() |
Get all unbound symbols, regardless of context:
In[12]:= |
![]() |
Out[12]= |
![]() |
Exclude specific contexts:
In[13]:= |
![]() |
Out[13]= |
![]() |
Excluded contexts using string patterns:
In[14]:= |
![]() |
Out[14]= |
![]() |
Exclude specified contexts in addition to the defaults:
In[15]:= |
![]() |
Out[15]= |
![]() |
Get dependent symbols in a definition while excluding local symbols:
In[16]:= |
![]() |
In[17]:= |
![]() |
Out[17]= |
![]() |
In[18]:= |
![]() |
Out[18]= |
![]() |
GetUnboundSymbols doesn’t predict future scoping:
In[19]:= |
![]() |
Out[19]= |
![]() |
In[20]:= |
![]() |
Out[20]= |
![]() |
When evaluated, x becomes a local symbol:
In[21]:= |
![]() |
Out[21]= |
![]() |
In[22]:= |
![]() |
Out[22]= |
![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License