BeginPackage
BeginPackage["context`"]
makes context` and System` the only active contexts.
BeginPackage["context`",{"need1`","need2`",…}]
calls Needs on the needi.
Details
- BeginPackage is typically used at the beginning of a Wolfram Language package.
- BeginPackage resets the values of both $Context and $ContextPath.
- The interpretation of symbol names depends on context. BeginPackage thus affects the parsing of input expressions.
Examples
open allclose allBasic Examples (1)
Commands to define a simple package:
The context for symbol creation has been changed to square`:
The context path for symbol lookup includes square`:
Here are the commands defining the function in the package:
Restore the context, but leave square` on the context path for symbol lookup:
Since EndPackage leaves square`square on the context path, the function defined is visible:
Scope (1)
Use BeginPackage and EndPackage to start and end a package in a file:
The package can be loaded with Get:
Properties & Relations (3)
BeginPackage["cont`"] sets $Context to "cont`":
EndPackage restores $Context to its value before the matching BeginPackage:
BeginPackage["cont`"] sets $ContextPath to {"cont`","System`"}:
EndPackage restores $ContextPath to its value before BeginPackage with "cont`" prepended:
BeginPackage does not alter the value of $ContextAliases:
EndPackage restores $ContextAliases to its value before the matching BeginPackage:
Text
Wolfram Research (1988), BeginPackage, Wolfram Language function, https://reference.wolfram.com/language/ref/BeginPackage.html.
CMS
Wolfram Language. 1988. "BeginPackage." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/BeginPackage.html.
APA
Wolfram Language. (1988). BeginPackage. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BeginPackage.html