Wolfram Research

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

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

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

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

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

Resource History

See Also

License Information