Re: using functions with package name prefixed.

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

On 1/16/04 at 6:04 AM, nma124 at hotmail.com (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 NumericalMath`Microscope`Ulp[1] 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