MathGroup Archive 1999

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

Search the Archive

Re: Help: Debuging Functions in Mathematica

  • To: mathgroup at
  • Subject: [mg16901] Re: [mg16860] Help: Debuging Functions in Mathematica
  • From: "Allan Hayes" <hay at>
  • Date: Tue, 6 Apr 1999 01:27:31 -0400
  • References: <7e9mci$>
  • Sender: owner-wri-mathgroup at

Jean-Marie, Boris

I think that Jean-Marie has probably dealt with this by explaining the
difference between Needs and Get,
but the following two remarks may be of use

Re the use of Clear in Jean-Marie's posting below ( at**).

I find the following framework convenient; with it old definitions are
automatically cleared when an edited and saved package file is loaded

Unprotect["`*"]; (*unprotect symbols in package context*)
ClearAll["`*"];   (*clear old assignments and attributes for symbols in
package context*)

ClearAll["`*"];  (*clear old assignments and attributes for symbols in
private package context*)


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


2.  We can arrange for a function's definition to be loaded when it is first
used in a session.
The following is a simple example - the same technique works for full

- make an m-file named "package1.m" in the directory
In this type the definition

fn1[x_] := x^2

- in the m-file Addons\Autoload\Kernel\init.m   (*which you may have to

(* Declarations for file mypacks`package1` *)

(* more functions, "fn2" ... ,might be added to the list {"fn1"} *)


After a kernel start the definition of fn1 will load automatically the first
time that it is used ( the package1.m will be loaded)


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

Jean-Marie THOMAS <jmthomas at> wrote in message
news:7e9mci$3he at
> Get or << reads in a file, while Needs performs the following task: if the
> context name (argument to Needs) is not already in the context path, calls
> Get to read the corresponding file, if the name is already in the context
> path, does NOTHING!
> I then suggest the following strategy:
> When writing a package (another useful suggestion is to use the package
> template provided by Roman Maeder, template normally provided in
> 3.0 distribution), set your directory to be the one containing the file
> "myNewPackage.m", read your definitions using Get["myNewPackage.m"] and
> debug! All changes you make to "myNewPackage.m" will then be read. Mind
> fact that writing definitions like foo[x_] will remain valid even if you
> change it to foo[x_someHead] or foo[x_,y_]. If necessary use:
>**  Clear at foo;Get["myNewPackage.m"];
> When you are finally through with debugging, place your package file
> wherever you want (AddOns/Autoload or AddOns/Applications, or somewhere in
> $Path), and make your call by Needs. If the file is neither in AddOns
> directories nor in $Path, use Needs[myContext,{PathTo myNewPackage}].
> Hope this helps,
> ****************************************
> Jean-Marie THOMAS
> mailto:jmthomas at
> Conseil et Audit en Ingenierie de Calcul
> Strasbourg, France
> ****************************************
> -----Original Message-----
> From: Boris Breznen [mailto:bbreznen at]
To: mathgroup at
> Subject: [mg16901] [mg16860] Help: Debuging Functions in Mathematica
> Boris

  • Prev by Date: ContourPlot: non-rectangular domains?
  • Next by Date: Re: question about entering vectors by the keyboard
  • Previous by thread: RE: Help: Debuging Functions in Mathematica
  • Next by thread: Re: Help: Debuging Functions in Mathematica