Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Temporarily set $Context and $ContextPath to a unique empty context for an evaluation
ResourceFunction["ContextModule"][expr] evaluates expr with $Context and $ContextPath set to an empty temporary context. |
Temporarily use an empty context:
In[1]:= |
Out[1]= |
The $ContextPath is also changed:
In[2]:= |
Out[2]= |
The values of $Context and $ContextPath are restored after evaluation of ContextModule:
In[3]:= |
Out[3]= |
In[4]:= |
Out[4]= |
Use Put to write an expression into a file with fully qualified symbol names:
In[5]:= |
In[6]:= |
Apply Compress to an expression so that it is not dependent on the current context:
In[7]:= |
Out[8]= |
This ensures that contexts are preserved when uncompressed in another session:
In[9]:= |
Out[9]= |
Without ContextModule, the symbols would take on whatever the current context is when uncompressed:
In[10]:= |
Out[10]= |
In[11]:= |
Out[11]= |
ContextModule always uses an empty context:
In[12]:= |
Out[12]= |
ContextModule is similar to Module in the sense that symbols created during the evaluation are not permanent:
In[13]:= |
Out[13]= |
In[14]:= |
Out[14]= |
In[15]:= |
Out[15]= |
In[16]:= |
Out[16]= |
Any symbols created in the temporary context are removed when the evaluation completes:
In[17]:= |
Out[17]= |
This also restores Contexts:
In[18]:= |
Out[20]= |
In[21]:= |
Out[21]= |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License