Needs

Needs["context`"]

loads an appropriate file if the specified context is not already in $Packages.

Needs["context`""alias`"]

loads the given context and establishes alias as a context alias for that context.

Needs["context`","file"]

loads file if the specified context is not already in $Packages.

Details

  • Needs["context`"] calls Get["context`"]. By convention, the file loaded in this way is the one that contains a package that defines context`.
  • Needs["context`"] automatically adds "context`" to $ContextPath, making all symbols in "context`" available without qualification.
  • Needs["context`""alias`"] adds "alias`""context`" to $ContextAliases, providing the ability to use a shorter or easier to type alias to access symbols in that context. Contexts loaded with this form are not added to $ContextPath.
  • Needs["context`"None] makes no modifications to $ContextPath or $ContextAliases.
  • Needs["file`"] typically reads in a file named .

Examples

open allclose all

Basic Examples  (2)

Read in the file for the Computer Arithmetic Package if it has not already been read:

The commands defined by the package are ready for use:

Read in the Computer Arithmetic package with the alias ca`:

Symbols can be accessed using the context alias:

Symbols can also be accessed using the original context name:

Scope  (1)

Read in the Computer Arithmetic package without adding it to the context path:

Using the function Ulp with the context fails:

Using the fully qualified name works:

Properties & Relations  (3)

The form Needs["context`""alias`"] modifies $ContextAliases:

The form Needs["context`"] modifies $ContextPath:

Once[Get[package]] is similar to Needs[package]:

Wolfram Research (1988), Needs, Wolfram Language function, https://reference.wolfram.com/language/ref/Needs.html (updated 2021).

Text

Wolfram Research (1988), Needs, Wolfram Language function, https://reference.wolfram.com/language/ref/Needs.html (updated 2021).

CMS

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

APA

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

BibTeX

@misc{reference.wolfram_2024_needs, author="Wolfram Research", title="{Needs}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/Needs.html}", note=[Accessed: 07-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_needs, organization={Wolfram Research}, title={Needs}, year={2021}, url={https://reference.wolfram.com/language/ref/Needs.html}, note=[Accessed: 07-November-2024 ]}