MathGroup Archive 2004

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

Search the Archive

Re: using functions with package name prefixed.

  • To: mathgroup at
  • Subject: [mg45662] Re: using functions with package name prefixed.
  • From: Bill Rowe <readnewsciv at>
  • Date: Sat, 17 Jan 2004 02:34:31 -0500 (EST)
  • Sender: owner-wri-mathgroup at

On 1/16/04 at 6:04 AM, nma124 at (steve_H) wrote:

> is there a way to use a function from a package without loading
> the whole package, but by simply prefixing the package name to 
> the function name?

While it is possible to use a function by prefixing the context, I am not aware of any method to load part of a package. 
> For an example, suppose we have a function foo[] in a packge called
> Boo.m
> Now, one must load the Boo package by typing something like
> Needs["`Boo"]
> then one can write
> foo[]
> But notice that when calling foo[], the package name is not prefixed to
> it, hence one does not know in which package foo[] is in by looking
> at the function call.

Right. In addition to loading the code in the package into memory, Needs adds the package context to $ContextPath. To evaluate expressions, Mathematica searches the contexts found in $Context path and evaluates it according to the first match it finds. This eliminates the need to specify the context path.

But, you can whenever you like specify the context path for Mathematica to use.

For example, after loading the package NumericalMath`Microscope` either

Ulp[1] or

will give the ulp on your machine near 1.
Note, I think of "package name" as being the filename of the code to be loaded. Perhaps you do as well. If so, it is important to realize it is the context path that must be prefixed not the package name. Typically, these are the same and the distinction I am making here is not important.
To reply via email subtract one hundred and four

  • Prev by Date: Re: Sort into chain
  • Next by Date: RE: Pipes Inside Mathematica?
  • Previous by thread: Re: using functions with package name prefixed.
  • Next by thread: Re: using functions with package name prefixed.