MathGroup Archive 2003

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

Search the Archive

Re: Options for my own Packages

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44258] Re: Options for my own Packages
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Fri, 31 Oct 2003 03:01:41 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

To answer a question on this subject David Park gave the following example:

Foo::usage = "Foo[x, opts...] is a routine that demonstrates the use of
options.  It returns 
p1 x^p2 where p1 and p2 are the values of the options FooParameter1 and
FooParameter2.";

FooParameter1::usage = "FooParameter1 is an option for Foo."; 
FooParameter2::usage = "FooParameter2 is an option for Foo.";

Options[Foo] = {FooParameter1 -> 1, FooParameter2 -> 2};

Foo[x_, opts___?OptionQ] := Module[{p1, p2}, 
    p1 = FooParameter1 /. {opts} /. Options[Foo];
     p2 = FooParameter2 /. {opts} /. Options[Foo]; 
    p1 x^p2 
] 

-------------------------------
To read my discussion on this subject goto 
   http://www.verbeia.com/mathematica/tips/Tricks.html
Then goto the section for (Options, OptionQ). 

Instead I use the following to get the option settings:


Options[Foo] = {FooParameter1 -> 1, FooParameter2 -> 2};

Foo[x_, opts___?OptionQ] := Module[{p1, p2}, 
    { p1, p2 } ={ FooParameter1, FooParameter2 } /. Flatten[{ opts,
Options[Foo] }]; 
    p1 x^p2 
] 

----------------------
This allows us give a list of options and get the desired result e.g.. 

In[4]:=   Foo[y, {FooParameter1->a, FooParameter2->b} ]

Out[4]=   a*y^b

----------------------
Regards,
   Ted Ersek


  • Prev by Date: Re: Options for my own Packages?
  • Next by Date: Re: Antw: pdf-export
  • Previous by thread: Bug or feature?Space and Return in source code
  • Next by thread: simple equation system -- crashing M5?