Quantcast
Channel: How to define a package without adding it to $ContextPath - Mathematica Stack Exchange
Viewing all articles
Browse latest Browse all 4

Answer by Joel Klein for How to define a package without adding it to $ContextPath

$
0
0

One way to do this is by taking note of how EndPackage works -- by adding \$Context to \$ContextPath:

ChurchNumerals`Private`prevContext = Context[];BeginPackage["ChurchNumerals`"];  ZERO::usage = "ZERO is the Church numeral encoding of zero";  ONE::usage = "ONE is the Church numeral encoding of the integer 1";  TWO::usage = "TWO is the Church numeral encoding of the integer 2";  Begin["`Private`"];    ZERO = Function[f, Function[n, n]];    ONE = Function[f, Function[n, f[n]]];    TWO = Function[f, Function[n, f[f[n]]]];  End[];  $Context = ChurchNumerals`Private`prevContext;EndPackage[];

Now the package is on $Packages but not $ContextPath, and is used qualified with the package name:

Map[#[Function[n, n + 1]][0] &,    {ChurchNumerals`ZERO, ChurchNumerals`ONE, ChurchNumerals`TWO}]

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>