MathGroup Archive 2003

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

Search the Archive

Re: The difference between Needs[ ] & Get[ ]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40186] Re: The difference between Needs[ ] & Get[ ]
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 25 Mar 2003 14:47:26 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <b5hd8c$mae$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

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.


  • Prev by Date: Re: Plot a recurrence relation
  • Next by Date: Unbelievable bug in ConstrainedMin, ConstrainedMax and LinearProgramming
  • Previous by thread: Re: The difference between Needs[ ] & Get[ ]
  • Next by thread: Running 4.0.1 under MacOSX-Classic?