Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: overloading a function name in a package? How to query all names?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110793] Re: overloading a function name in a package? How to query all names?
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Wed, 7 Jul 2010 07:40:51 -0400 (EDT)
  • References: <i0urgq$6kp$1@smc.vnet.net>

Am 06.07.2010 11:03, schrieb Nasser M. Abbasi:
> Hello;
> 
> I have package where I overloaded the same function name, defined to 
> accept different arguments. as follows:
> 
> -------------------
> BeginPackage["foo`"]
> 
> boo1::usage="call me as follows: boo1[a,b]"
> boo1::usage="call me as follows: boo1[a]"



> Begin["`Private`"]
> 
> boo1[a_,b_]:=Module[{},Print["in v1 of boo1"]];
> 
> boo1[a_]:=Module[{},Print["in v2 of boo1"]];
> 
> End[]
> EndPackage[]
> --------------------------------
> 
> Now, I do
> 
> <<foo`
> 
> And I can call either of them OK
> 
> boo1[1,2]
> boo1[1]
> 
> 
> But when I do
> 
> Names["foo`*"]
> 
> It only shows name boo1 once. (I can understand this*)
> 
> And when I do
> 
> ?foo`*
> 
> It only list boo1 once. It seems to show the ::usage of the last one. 
> OK. I can understand this.
> 
> But, then, is there a way to show the user than I have more than one 
> version of the same function name in the package? Without having to look 
> into the package file?

you need to understand that there are not two functions, but only two
patterns for the same symbol. And one symbol can have only one usage
message and of course, it only exists once. The situation is very
common, though, and many Mathematica symbols (functions) have more than
one pattern defined for them. What you usually want to do is to put all
available possiblities to call the function in the one usage message, e.g.:

boo1::usage="call me as follows: boo1[a,b] or boo1[a]"

Of course you can also just look at the DownValues of the symbols to see
all the definitions:

DownValues[boo1]

but that is probably not the right way to document your function for
others...

hth,

albert


  • Prev by Date: Re: Run Package vs Needs
  • Next by Date: Re: The side-effects of mixing TraditionalForm inside
  • Previous by thread: Re: overloading a function name in a package? How to query all names?
  • Next by thread: Re: overloading a function name in a package? How to query all names?