Function Repository Resource:

UniqueContext

Source Notebook

Provide a new context that contains no symbols

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["UniqueContext"][]

returns a string corresponding to a context that has no symbols.

ResourceFunction["UniqueContext"][name]

returns an empty context based on name.

Examples

Basic Examples (2) 

Retrieve the ResourceFunction:

In[1]:=
ResourceFunction["UniqueContext"]
Out[1]=

Get a string corresponding to a context with no existing symbols:

In[2]:=
ResourceFunction["UniqueContext"][]
Out[2]=

Scope (2) 

A base name can be given:

In[3]:=
ResourceFunction["UniqueContext"]["MyContext`"]
Out[3]=

If symbols already exist in a context, it will be skipped:

In[4]:=
MyContext$2`x = 1;
ResourceFunction["UniqueContext"]["MyContext`"]
Out[5]=

Generalizations and Extensions (1) 

With no arguments given, the context name will be based on the current value of $Context:

In[6]:=
Block[{$Context = "NewContext`"},
 ResourceFunction["UniqueContext"][]
 ]
Out[6]=

Applications (1) 

Create a string that has fully qualified symbol names:

In[7]:=
empty = ResourceFunction["UniqueContext"][];
Block[{$Context = empty, $ContextPath = {empty}},
 ToString[FullForm[a + b]]
 ]
Out[8]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 11 October 2018

Related Resources

License Information