Re: Mma Package Style Question
- To: mathgroup at smc.vnet.net
- Subject: [mg8474] Re: [mg8399] Mma Package Style Question
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Tue, 2 Sep 1997 16:15:11 -0400
- Sender: owner-wri-mathgroup at wolfram.com
"Xah" <xah at best.com> in [mg8399] Mma Package Style Question writes >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Normaly, the usage message for exported functions are placed between BeginPackage["xxx`"] and Begin["`Private"], but I like to place my functiondefinitions and usage message together in the Private section of the package, for easy development and maintenance. My question is, are there ANY foreseeable reason not to do this? I'd appreciate any help from wri fellow. Thanks. (below is an example of how my package might look like) -------------------------------- BeginPackage["blur`"] Clear[fff,ggg,...]; Begin["`Private`"] fff::usage="fff blurs your memory"; fff::err="You've erred in this and that way." fff[_]:=Print["Your memory is now blured."]; ggg::usage="ggg[] gives you a hynosis." ggg[_]=Print["Your memory was blurred."]; ... End[ ] Protect[ fff,ggg,... ] EndPackage[ ] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Xah, Your OK so long as you first introduce the symbols to be exported between BeginPackage[..] and Begin[.]. They will then be created in the Package context. This you do with Clear[fff,ggg...] Any symbol hh that is introduced first between Begin[.] and End[] will be created in the context "Private`blur" , its long name will be blur`Private`hh and and will not be accessible by its short name hh. You might like to consider preceding Clear[..] with Unprotect[...] otherwise, on reloading, the protection given at the end will prevent clearing and give rise to messages. The normal pattern protects one a little against forgetting to create exported symbols properly. Incidentally, your positioning would not allow you to use one of my favourite tricks : Unprotect["`*"], Unprotect["`*"] which automatically deal with all package context symbols -- unless you introduced all exported symbols some other way before Begin[]. Allan Allan Hayes hay at haystack.demon.co.uk http://www.haystack.demon.co.uk/training.html voice:+44 (0)116 2714198 fax: +44 (0)116 2718642 Leicester, UK