Skip to content

$ContextPath

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

$ContextPath is a list of contexts used (in order) to resolve bare
identifiers to existing qualified symbols. Modified by BeginPackage[]
and EndPackage[].

Examples

No verified examples yet for this function.

Implementation notes

Not a builtin: $ContextPath is a symbol whose OwnValue tracks the internal search path g_path (a char** of context strings, most-specific first) in src/context.c. republish_state rebuilds it via publish_own("$ContextPath", context_path_as_list()), which materialises the g_path entries into a List of strings. It is ATTR_PROTECTED; the list is only mutated by BeginPackage (which resets the path to {ctx, System} plus any Needs contexts) and EndPackage (which prepends the just-closed package context). context_resolve_name walks this path in order to resolve a bare name to an existing qualified symbol.

Attributes: Protected.

Implementation status

Stable — documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

References

Notes & additional examples

Worked examples

In[1]:= $ContextPath
Out[1]= {"Global`", "System`"}

In[2]:= BeginPackage["MyPkg`"]
Out[2]= "MyPkg`"

In[3]:= $ContextPath
Out[3]= {"MyPkg`", "System`"}

Notes

$ContextPath is the ordered list of contexts searched to resolve bare identifiers to existing qualified symbols. It is read-only for direct assignment and is modified by BeginPackage and EndPackage.