[Date Index] [Thread Index] [Author Index]
Re: The difference between Needs[ ] & Get[ ]
Hi, Get can load any Mathematica commands written in a ASCII file. The kernel will execute the commands and return (possibly with the result of the last evaluated statement). Needs check the $ContextPath, for a given context and if the context is not present, it try to find a package (due to the name of the context) load it and add update the context. Needs can only work with packages that add a new context, but you can Get any sequence of Mathematica commands. If Needs find a ASCII file *.m (with Mathematica commands) it load the file, but if the file create not a new context you get the error message below. If you have a package that create an new context, Needs is better because it avoid a second loading of a package that the kernel has already loaded. One exeption for packages is, if you are modify the contents of the package (say with a external ASCII editor) that you should use Get because otherwiese the kernel willnot reload the file and update the changed definitions. Regards Jens neuron wrote: > > Hello MathGroup gurus, > I am new to Mathematica and now reading "Programming In Mathematica." > I am a little confused with Needs[ ] & Get[ ]. > I kow that Needs[ ] checks $Packages whether the package is present or > not and I usually use Needs[ ] to load a package. > On the xiv page of "ProgrammingInMathematica" it says "Even better is > Needs["ProgrammingInmathematica`Package`"]........" > but on page 13, > when I input > Needs["ProgrammingInMathematica`ComplexMap1`"] > instead of > <<ProgrammingInMathematica`ComplexMap1` > an error occurs: > Needs::nocont: Context ProgrammingInMathematica`ComplexMap1` was not > created when Needs was evaluated. > > I don't know why, for the Help says "Needs["context`"] calls > Get["context`"]. By convention, the file loaded in this way is the one > which contains a package that defines context`. " > > I execute Mathematica 4.1 on Windows98 > > Thanks for any advice.