MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: package construction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117989] Re: package construction
  • From: Alexey <lehin.p at gmail.com>
  • Date: Thu, 7 Apr 2011 08:06:29 -0400 (EDT)
  • References: <inerrp$jae$1@smc.vnet.net> <inhaph$28b$1@smc.vnet.net>

"Sjoerd C. de Vries" <sjoerd.c.devr... at gmail.com> wrote:
> This is from tutorial/SettingUpMathematicaPackages. It doesn't look
> that complicated to me...
>
> BeginPackage["Collatz`"]
>
> Collatz::usage =
>         "Collatz[n] gives a list of the iterates in the 3n+1 problem,
>         starting from n. The conjecture is that this sequence always
>         terminates."
>
> Begin["`Private`"]
>
> Collatz[1] := {1}
> Collatz[n_Integer]  := Prepend[Collatz[3 n + 1], n] /; OddQ[n] && n >
> 0
> Collatz[n_Integer] := Prepend[Collatz[n/2], n] /; EvenQ[n] && n > 0
>
> End[ ]
> EndPackage[ ]

The key thing that should be added here is that one must create (= use
in any way) all the symbols that must be accessible outside of the
package *before* Begin["`Private`"]. In this case they will be in the
Collatz` context (in the example above) and they will be in the
$ContextPath after loading of the package.

Alexey


  • Prev by Date: Re: Interpolation on regions
  • Next by Date: Re: Picking certain values from an array of solutions
  • Previous by thread: Re: package construction
  • Next by thread: package construction