Mathematica 9 is now available
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: [mg110796] Re: overloading a function name in a package? How to query all names?
  • From: "David Park" <djmpark at comcast.net>
  • Date: Wed, 7 Jul 2010 07:41:24 -0400 (EDT)

Nasser,

One symbol, one usage message. But the usage message can contain variants in
the usage.

boo1::usage = 
  "boo1[a] returns the quaternion norm.\nboo1[a, b] divides \
quaternion a by quaternion b.";

Also, if a usage message starts with the name of the function and primary
calling sequence Mathematica can use that to implement command completion
for that function.

I hope that someday WRI will consider reworking the usage message
technology.

1) A string is hopelessly out of date and they might switch to using a
Mathematica expression that might, among other things, contain embedded
information on command completion.

2) Functions that have sub values, e.g, boo2[parm1, parm2][x, y], do not
generate the entire pattern on command completion.

3) Often it is a bit tricky to get everything to work correctly when there
are box structures inside the string. I've seen problems with the
combination of box structures and the use of the "\n" new line command. It
helps to convert the string to InputForm and copy that into the usage
message.

4) Usage message cells do not allow individual magnification in notebooks as
can be done with other cell types. It would often be useful to enlarge
particular usage messages if they are packed with a lot of detail and box
structures.

If you would like to see better usage messages, please join the UMLF. (Usage
Message Liberation Front.)

Also, if you are doing Workbench documentation don't include Greek or
special characters in a package function name. This is because Workbench
generates a Function page notebook for each symbol (that's the Help page for
the symbol) and most operating systems won't accommodate file names with
Greek or special characters.


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  


From: Nasser M. Abbasi [mailto:nma at 12000.org] 

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?

I'd like to overload the function name, since I need to call it 
differently sometimes, and I do not want to make up new names of the 
same function, as in booV1[], booV2[], etc... since they all do the same 
logical action, but accept different arguments depending on the options 
needed, and so they all just have the same name, and the correct version 
will be called depending on the arguments used.

Overloading works OK when calling. I am just asking on how to show that 
I have more than one function of the same name in the package, so I know 
how to call each one.

I looked a the docs, but so far, did not see anything. will keep looking....

thanks
--Nasser





  • Prev by Date: Re: Defining UpValues
  • Next by Date: Re: Defining UpValues
  • 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?