Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

Re: creating packages

  • To: mathgroup at
  • Subject: [mg32907] Re: creating packages
  • From: "Allan Hayes" <hay at>
  • Date: Tue, 19 Feb 2002 02:29:35 -0500 (EST)
  • References: <a4qlhe$eob$>
  • Sender: owner-wri-mathgroup at


I hope that he following may help - fo rmore see  Roman Maeder's book
"Programming in Mathematica"

I'll go through one way of creating a short package,'

It must be a text file file with extension m, here the file will be named
I will put in the ExtraPackages/haypacks//Graphics/
(the address of ExtraPackages is given by evaluating
    ToFileName[{$TopDirectory, "AddOns", "ExtraPackages"}]
This will enable me to load the package with the command
(or Get["haypacks`Graphics`RandomCharts` "] or
Needs["haypacks`Graphics`RandomCharts` "] )

Here is the package code to be put into the file, this may be varied.
(you can type it directly into the file - there are other ways)
(* ....*) are my comments - not essential to the code.

        (*begin the package context, load Graphics`Graphics` needed for the
function BarChart*)

        (*unprotect and clear out old definitionsn - allows repeated loading
and alterations*)

    RandomBarChart::usage="RandomBarChart[n] for a positive integer n
displays a
    bar chart for n random numbers "
        (*usage message:gives info via ?RandomBarChart*, makes
RandomBarChart available to user)

    (*begins the package's private context; this is where you working code
    vals=..., below, is internal to the package, not meant to be used
directly by user *)

    vals[n_] = Table[Random[], {n}];
    RandomBarChart[n_]:= BarChart[vals[n]];

    End[];  (*end private context*)

    Protect["`*"] (*protect all symbols in the package context")

    EndPackage[]; (*end package context

? each of the expressions BeginPackage[..], Begin[..], End[] and
EndPackage[]must be in its own input line


Allan Hayes
Mathematica Training and Consulting
Leicester UK
hay at
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"poonam" <poonam_pandey at> wrote in message
news:a4qlhe$eob$1 at
> I am a first time user of mathematica and currently using version 4.0.
> I am trying to create a package. I am not very clear about how and
> where to write the package. I tried to use the dumpsave method, but
> its not creating the binary format .mx file. Where do i have to write
> the package .nb or in text editor and how do i run the dumpsave
> command? Or do i need to do this in text editor and save as .m?
> Can somebody clear my doubts. ?
> Thanks

  • Prev by Date: Re: Re: partial fraction
  • Next by Date: RE: creating packages
  • Previous by thread: RE: creating packages
  • Next by thread: RE: creating packages