Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Similar to Block, except values of local symbols are not cleared when entering the block
ResourceFunction["InheritedBlock"][{x,y,…},expr] specifies that expr is to be evaluated with changes to the symbols x,y,… localized to the block. | |
ResourceFunction["InheritedBlock"][{x=x0,…},expr] defines initial local values for x,…. |
Make temporary changes to the value of a symbol:
| In[1]:= |
| Out[2]= |
The original value is restored:
| In[3]:= |
| Out[3]= |
Temporarily modify definitions of a function:
| In[4]:= |
| Out[5]= |
The changes to the definition of f only persisted within the block:
| In[6]:= |
| Out[6]= |
Make temporary changes to multiple symbols:
| In[7]:= |
| Out[8]= |
Both symbols are restored:
| In[9]:= |
| Out[9]= |
Modify Protected functions for one evaluation:
| In[10]:= | ![]() |
| Out[10]= |
The normal behavior is unchanged:
| In[11]:= |
| Out[11]= |
The Attributes are restored as well:
| In[12]:= |
| Out[12]= |
Temporarily change the default formatting of expressions:
| In[13]:= | ![]() |
| Out[13]= |
Have cloud deployments that would otherwise be deployed to anonymous cloud objects go to a specific target:
| In[14]:= | ![]() |
| Out[14]= |
The normal behavior is unchanged:
| In[15]:= |
| Out[15]= |
InheritedBlock localizes values only; it does not create new symbols:
| In[16]:= |
| In[17]:= |
| Out[17]= |
Module creates new symbols:
| In[18]:= |
Using Condition in InheritedBlock does not work the same way as Block, Module and With:
| In[19]:= | ![]() |
| Out[20]= |
The behavior is also different for held replacements:
| In[21]:= |
| Out[21]= |
| In[22]:= |
| Out[22]= |
| In[23]:= |
| Out[23]= |
| In[24]:= |
| Out[24]= |
Symbols cleared with ClearAll within an InheritedBlock will not be restored:
| In[25]:= | ![]() |
| Out[23]= |
Compare to Block, which protects its symbols from ClearAll:
| In[26]:= | ![]() |
| Out[27]= |
Clear is safe to use:
| In[28]:= | ![]() |
| Out[29]= |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License