MathGroup Archive 1999

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

Search the Archive

RE: Help: Debuging Functions in Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16876] RE: [mg16860] Help: Debuging Functions in Mathematica
  • From: "Jean-Marie THOMAS" <jmthomas at agat.net>
  • Date: Mon, 5 Apr 1999 02:24:18 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

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: [mg16876] [mg16860] Help: Debuging Functions in Mathematica


This is a newbie question:

I am migrating from Matlab to Mathematica, but I find the transition
extrmemely painful (to the point of re-evaluating my decision). Here
is a trivial problem that I spent last 2 days trying to solve. When
you write a function in Matlab, you save it to a text file with
extension .m and then simply type the name of the file (function)
at the Matlab prompt to use it. When
you make changes in the source code you type "clear myFunction"
at matlab prompt, which removes the function definition and then
re-type the function name again. As simple as it gets ...

Now, how do you do the same thing in Mathematica ? I have
a function that I saved in a package format. The directory
that contains the package is part of the $Path. When I put
Needs["myFunction`"] in a notebook the function works fine.
But now I want to change the source code. I edit the package,
go back to the notebook type Remove[myFunction] and at that
point Mathematica refuses to read the function again. Doesn't
matter if I use Needs, or <<, Mathematica doesn't re-load the
function. How the hell do you do this trivial task ?

Thank you

Boris




  • Prev by Date: RE: extracting lhs or rhs of equations
  • Next by Date: Eigenvalue Problem
  • Previous by thread: Help: Debuging Functions in Mathematica
  • Next by thread: RE: Help: Debuging Functions in Mathematica