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: [mg44243] Re: Options for my own Packages?
  • From: poujadej at yahoo.fr (Jean-Claude Poujade)
  • Date: Fri, 31 Oct 2003 03:01:08 -0500 (EST)
  • References: <bnlidb$p92$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Steven T. Hatton" <hattons at globalsymmetry.com> wrote in message news:<bnlidb$p92$1 at smc.vnet.net>...
> Can I create and use options in my own packages?  I've seen comments in the
> help documentation that say "built-in functions" have options.  Here's an
> example of what I want.  I created a class called curveGrid, which has data
> and methods for generating a coordinate grid defined by a mapping function
> passed to the constructor.  I would like to be able to set an option that
> changed the default color of all instances of this class.
> 
> Is there a way to accomplish this so that I can do something like
> SetOptions[curveGrid,name->value, name2->value2...]?

Here is an example after the book "Programming in Mathematica" by Roman Maeder:

In[1]:= Options[f] = {Opt1 -> True, Opt2 -> True};

f[n_, opts___Rule]:=
Module[{opt1, opt2},
   opt1 = Opt1 /. {opts} /. Options[g];
   opt2 = Opt2 /. {opts} /. Options[g];
   {n,opt1,opt2}
];

f[1]

Out[1]={1,True,True}

In[2]:= f[1, Opt2 -> False]
Out[2]={1,True,False}

hth
---
jcp


  • Prev by Date: Re: Full error messages?
  • Next by Date: Re: Options for my own Packages
  • Previous by thread: RE: Options for my own Packages?
  • Next by thread: Mathematica Wish-List