Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: using functions with package name prefixed.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45723] Re: using functions with package name prefixed.
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Wed, 21 Jan 2004 04:55:08 -0500 (EST)
  • Organization: The University of Western Australia
  • References: <bu8gma$aiu$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <bu8gma$aiu$1 at smc.vnet.net>, 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?

No. But you can set things up (e.g using Master.m and Kernel`init` as 
used in the StandardPackages) to automatically load a (full) required 
package in which a particular function resides. For example,

   <<Graphics`

   LogPlot[Exp[x], {x, 0, 10}]
 
> 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.

However, after your Needs (or Get) command has been executed, you can 
call a function with the explicit package name. E.g,

  Graphics`Graphics`LogPlot[Exp[x], {x, 0, 2}]

works (because the Context of LogPlot is Graphics`Graphics`).
 
> In Java for instance, I can write Boo.foo(), which makes it more
> clear where foo() is located.

So you can (sort of) do this. If you put each function into a separate 
package you could do what you want to do, though this would be rather 
clumsy in Mathematica.

Cheers,
Paul

-- 
Paul Abbott                                   Phone: +61 8 9380 2734
School of Physics, M013                         Fax: +61 8 9380 1014
The University of Western Australia      (CRICOS Provider No 00126G)         
35 Stirling Highway
Crawley WA 6009                      mailto:paul at physics.uwa.edu.au 
AUSTRALIA                            http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: Tail recursion and local functions
  • Next by Date: Re: AW: Loading a Package
  • Previous by thread: Re: using functions with package name prefixed.
  • Next by thread: Mathematica for Macintosh questions.