$ContextPath

$ContextPath

is a global variable that gives a list of contexts to search, before $Context, in trying to find a symbol that has been entered.

Details

  • Each context is specified by a string of the form "name`".
  • The elements of $ContextPath are tested in order to try to find a context containing a particular symbol.
  • $ContextPath is modified by BeginPackage and EndPackage.
  • $ContextPath is a rough analog for Wolfram Language symbols of the "search path" for files in many operating systems.

Examples

open allclose all

Basic Examples  (2)

The default contexts for looking up symbols:

The symbol Integrate can be found because it is in the "System`" context:

If a symbol with a given name is not found in one of the contexts in $ContextPath, it will be created:

It is created in the context given by $Context:

Turn off the message for new symbol creation:

Scope  (2)

$ContextPath must always be a list of strings:

Both simple and compound contexts can be included in $ContextPath:

Applications  (1)

Add Developer` context to the context path:

PackedArrayForm is a command in the Developer` context that can now be used directly:

Restore the previous context path:

Properties & Relations  (6)

Symbols on $ContextPath are found before symbols in $Context with the same name:

System`Grad is found because "System`" is by default a member of $ContextPath:

Contexts on $ContextPath are searched in order:

Reversing the order of "cont1`" and "cont2`" changes which x is found:

If an input symbol contains context marker (`), $ContextPath is ignored:

The variable x in the current context is found:

However, inner`x is not appended to "outer`", which is on the path, to form outer`inner`x:

BeginPackage changes $ContextPath to consist of "System`" and the package context:

EndPackage restores the previous value of $ContextPath with the package context prepended:

Begin does not alter the value of $ContextPath:

Neither does End:

An active context alias cannot be added to $ContextPath:

Wolfram Research (1988), $ContextPath, Wolfram Language function, https://reference.wolfram.com/language/ref/$ContextPath.html (updated 2007).

Text

Wolfram Research (1988), $ContextPath, Wolfram Language function, https://reference.wolfram.com/language/ref/$ContextPath.html (updated 2007).

CMS

Wolfram Language. 1988. "$ContextPath." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2007. https://reference.wolfram.com/language/ref/$ContextPath.html.

APA

Wolfram Language. (1988). $ContextPath. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/$ContextPath.html

BibTeX

@misc{reference.wolfram_2024_$contextpath, author="Wolfram Research", title="{$ContextPath}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/$ContextPath.html}", note=[Accessed: 05-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_$contextpath, organization={Wolfram Research}, title={$ContextPath}, year={2007}, url={https://reference.wolfram.com/language/ref/$ContextPath.html}, note=[Accessed: 05-November-2024 ]}