Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2010

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

Search the Archive

Re: how to create a mathematica package

  • To: mathgroup at
  • Subject: [mg111134] Re: how to create a mathematica package
  • From: "Nasser M. Abbasi" <nma at>
  • Date: Wed, 21 Jul 2010 07:14:22 -0400 (EDT)
  • References: <i199df$q4p$> <i20q7s$kid$> <i23k2u$erk$>
  • Reply-to: nma at

On 7/20/2010 12:43 AM, Istv=E1n Zachar wrote:
> I think you should also protect the public variables of the package at
> the end to prevent the user to overwrite them.
> Istvan

When you said the above, I made some experiments, and I think what I
need to do in addition to what you said is to also Clear the function nam=

So, now I have it like this:

f::usage = "f[x]"

f[x_] := Module[{}, x^2];


The Unprotect[f] is needed for the case when the package is reloaded
again, else one will get an error trying to define something already
protected (from the first loading)

The Clear[f] is needed, because suppose I had written


Then wanted to load the package


Then I would get an error trying to define a function 4[x_]. This is
Unprotect[f] does not also Clear[f]. So needed to explicitly do a Clear[f=

The last Protect is needed to prevent me from overwriting the name of
the function 'f' after I have loaded the package as in:


Does the above seem like the canonical package layout for a simple

I've also corrected couple of typos (thanks Bill Rowe) and updated the no=

If I can improve this more, pls let me know.


  • Prev by Date: Re: Show left hand side
  • Next by Date: Strange 26base enumeration
  • Previous by thread: Re: how to create a mathematica package
  • Next by thread: Re: how to create a mathematica package