Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #1523
| From | Alexey <lehin.p@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: package construction |
| Date | 2011-04-07 12:06 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <ink9cj$gbh$1@smc.vnet.net> (permalink) |
| References | <inerrp$jae$1@smc.vnet.net> <inhaph$28b$1@smc.vnet.net> |
"Sjoerd C. de Vries" <sjoerd.c.devr...@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
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
package construction Jack L Goldberg 1 <jackgold@umich.edu> - 2011-04-05 10:45 +0000
Re: package construction "Sjoerd C. de Vries" <sjoerd.c.devries@gmail.com> - 2011-04-06 09:12 +0000
Re: package construction Alexey <lehin.p@gmail.com> - 2011-04-07 12:06 +0000
Re: package construction "Nasser M. Abbasi" <nma@12000.org> - 2011-04-06 09:14 +0000
csiph-web