Re: Help: Debuging Functions in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg16901] Re: [mg16860] Help: Debuging Functions in Mathematica
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Tue, 6 Apr 1999 01:27:31 -0400
- References: <7e9mci$3he@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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 1. 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 BeginPackage[..]; Unprotect["`*"]; (*unprotect symbols in package context*) ClearAll["`*"]; (*clear old assignments and attributes for symbols in package context*) Begin["`Private`"]; ClearAll["`*"]; (*clear old assignments and attributes for symbols in private package context*) End[]; Protect["`*"]; (*protect symbols in package context*) EndPackage[] 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 packages - make an m-file named "package1.m" in the directory Addons\ExtraPackages\mypacks In this type the definition fn1[x_] := x^2 - in the m-file Addons\Autoload\Kernel\init.m (*which you may have to make*) type (* Declarations for file mypacks`package1` *) DeclarePackage[ "mypacks`package1`", {"fn1"} ] (* more functions, "fn2" ... ,might be added to the list {"fn1"} *) Save. 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 --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 Jean-Marie THOMAS <jmthomas at agat.net> wrote in message news:7e9mci$3he at smc.vnet.net... > 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 Mathematica > 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 the > 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 agat.net > Conseil et Audit en Ingenierie de Calcul > Strasbourg, France > http://www.agat.net > **************************************** > > -----Original Message----- > From: Boris Breznen [mailto:bbreznen at vis.caltech.edu] To: mathgroup at smc.vnet.net > Subject: [mg16901] [mg16860] Help: Debuging Functions in Mathematica > ......... > Boris