Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Provide a new context that contains no symbols
| ResourceFunction["UniqueContext"][] returns a string corresponding to a context that has no symbols. | |
| ResourceFunction["UniqueContext"][name] returns an empty context based on name. | 
Retrieve the ResourceFunction:
| In[1]:= | ![ResourceFunction["UniqueContext"]](https://www.wolframcloud.com/obj/resourcesystem/images/9b2/9b241785-ff05-46f0-8e66-7be3ec7aec3e/3d703591e3887531.png) | 
| Out[1]= |  | 
Get a string corresponding to a context with no existing symbols:
| In[2]:= | ![ResourceFunction["UniqueContext"][]](https://www.wolframcloud.com/obj/resourcesystem/images/9b2/9b241785-ff05-46f0-8e66-7be3ec7aec3e/2dc8b1ddb70dcde7.png) | 
| Out[2]= |  | 
A base name can be given:
| In[3]:= | ![ResourceFunction["UniqueContext"]["MyContext`"]](https://www.wolframcloud.com/obj/resourcesystem/images/9b2/9b241785-ff05-46f0-8e66-7be3ec7aec3e/1a35c7f3110a2115.png) | 
| Out[3]= |  | 
If symbols already exist in a context, it will be skipped:
| In[4]:= | ![MyContext$2`x = 1;
ResourceFunction["UniqueContext"]["MyContext`"]](https://www.wolframcloud.com/obj/resourcesystem/images/9b2/9b241785-ff05-46f0-8e66-7be3ec7aec3e/120ef313e93c8afc.png) | 
| Out[5]= |  | 
With no arguments given, the context name will be based on the current value of $Context:
| In[6]:= | ![Block[{$Context = "NewContext`"},
 ResourceFunction["UniqueContext"][]
 ]](https://www.wolframcloud.com/obj/resourcesystem/images/9b2/9b241785-ff05-46f0-8e66-7be3ec7aec3e/470d3eee016bdd89.png) | 
| Out[6]= |  | 
Create a string that has fully qualified symbol names:
| In[7]:= | ![empty = ResourceFunction["UniqueContext"][];
Block[{$Context = empty, $ContextPath = {empty}},
 ToString[FullForm[a + b]]
 ]](https://www.wolframcloud.com/obj/resourcesystem/images/9b2/9b241785-ff05-46f0-8e66-7be3ec7aec3e/5bd8597b557a85a3.png) | 
| Out[8]= |  | 
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License