$ContextAliases

$ContextAliases

is a global variable that gives an association with mappings from aliases to contexts.

Details

  • $ContextAliases takes the form <|"alias1`""context1`","alias2`""context2`",|>, where aliasi can be any string of characters that could be used to create a legal symbol name. contexti must be a fully qualified context name.
  • An alias can be used in place of a fully qualified context when referring to symbols. For a given symbol context`symbol, the name alias`symbol may be used in its place.
  • $ContextAliases can be modified directly. It is also updated automatically by calls to Needs, EndPackage and End. »

Examples

open allclose all

Basic Examples  (1)

Define a symbol in a specific context:

Create an alias for Context1`Context2`:

Use the alias to reference the symbol:

Delete the alias:

Scope  (8)

Creating Context Aliases  (4)

$ContextAliases must be an association with entries of the form "alias""context`":

Aliases cannot represent relative contexts:

Aliases must form legal symbol names:

Needs can create a context alias:

Use PackedArrayQ from the Developer Utilities Package:

Since "Developer`" is not on $ContextPath, the unqualified symbol name is not resolved:

Using Context Aliases  (4)

Aliases are resolved before creating new symbols:

An alias may represent multiple levels of contexts:

All ways of typing in a symbol respect context aliases:

Clear a single alias:

Clear all context aliases:

Properties & Relations  (9)

Context aliases work in ToExpression:

A context alias is resolved in held evaluations:

Symbol resolves context aliases:

Changes made to aliases after BeginPackage will be restored after the matching EndPackage:

End restores $ContextAliases to the value it had before the matching Begin:

Names resolves context aliases by default:

Use the ResolveContextAliases option to prevent alias resolution:

NameQ behaves identically:

Contexts resolves aliases by default:

Use the ResolveContextAliases option to prevent alias resolution:

Information resolves aliases by default:

Information also uses aliases when resolving string patterns:

Use the ResolveContextAliases option to prevent alias resolution:

An active alias cannot be added to $ContextPath:

Possible Issues  (1)

Aliases can mask existing contexts:

Because of the aliases, the symbol cont`x is not accessible:

Removing the clashing alias will restore access to the masked context:

Wolfram Research (2021), $ContextAliases, Wolfram Language function, https://reference.wolfram.com/language/ref/$ContextAliases.html.

Text

Wolfram Research (2021), $ContextAliases, Wolfram Language function, https://reference.wolfram.com/language/ref/$ContextAliases.html.

CMS

Wolfram Language. 2021. "$ContextAliases." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/$ContextAliases.html.

APA

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

BibTeX

@misc{reference.wolfram_2024_$contextaliases, author="Wolfram Research", title="{$ContextAliases}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/$ContextAliases.html}", note=[Accessed: 06-October-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_$contextaliases, organization={Wolfram Research}, title={$ContextAliases}, year={2021}, url={https://reference.wolfram.com/language/ref/$ContextAliases.html}, note=[Accessed: 06-October-2024 ]}