Re: Options[] in Mathematica 4.1

*To*: mathgroup at smc.vnet.net*Subject*: [mg28728] Re: Options[] in Mathematica 4.1*From*: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>*Date*: Fri, 11 May 2001 03:38:45 -0400 (EDT)*Organization*: Universitaet Leipzig*References*: <9de1iq$gup@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Hi, a) avoid Rule, it is in the System` context an too important b) document the functions and options by placing usage information into the right context i.e ------------------------------------------------------------------------ BeginPackage["MyPackage`"] UseFullFunction::usage="UseFullFunction[arg,opts] make nothing usefull." MyRule::usage="MyRule is an option for UseFullFunction[]" (* now MyRule is in the context MyPackage` and full qualified by MyPackage`MyRule` *) Begin["`Private`"] Options[UseFullFunction]={MyRule->True} UseFullFunction[arg_,opts___]:= Module[{myrule}, myrule=MyRule /. {opts} /. Options[UseFullFunctions]; ] End[] EndPackage[] ------------------------------------------------------------------------- and with ------------------------------------------------------------------------- MyRule::usage="MyRule is an option for UseFullFunction[]" (* now MyRule is in the context Global` and full qualified by Global`MyRule` *) BeginPackage["MyPackage`"] UseFullFunction::usage="UseFullFunction[arg,opts] make nothing usefull." Begin["`Private`"] Options[UseFullFunction]={MyRule->True} UseFullFunction[arg_,opts___]:= Module[{myrule}, myrule=MyRule /. {opts} /. Options[UseFullFunctions]; ] End[] EndPackage[] -------------------------------------------------------------------------- Your second problem: yes, you can because the option Options[MyFunction]={PlotRange->Automatic} will only used in your functions and not by the system functions. Since PlotRange is already in the system context, no new variable in the private context is created. Regards Jens James Jones wrote: > > Hi, > > I have written several functions which take optional rules as arguments. > Upto now I have been parsing the rules inside the functions with > > rule = Global`Rule /. {options} /. {Global`Rule -> True}; etc, > > however I think this is causing problems with some other built in functions > (where my option names are the same?). I have Seen another package (CERN's > mfs package) use > > Options[function] = {Rule -> True} > > then parsed as > > rule = Global`Rule /. {options} /. Options[myfunction]; etc, > > there doesn't appear to be any problems with this. However if I try this > with my functions, which are in a Private context and read in as part of a > package, and type Options[Myfunction] I get > > { Madtomma`madinput`madinput`Private`Rule -> True } > > and the rules don't work properly. I can solve this by placing the > Options[myfunction] outside the private context of my package, but I was > wondering how it can be left next to the function definition in the private > context? > > On a related point, if I have rules that have the same name as built in > rules (say PlotRange for some of my plotting functions) can I use these and > not affect the built in functions? > > Any help much appreciated, > > James Jones > Daresbury Lab.