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: [mg44226] RE: [mg44212] Options for my own Packages?
  • From: "David Park" <djmp at earthlink.net>
  • Date: Wed, 29 Oct 2003 03:34:07 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Steven,

Here is an 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
    ]

Foo[y]
y^2

Foo[y, FooParameter1 -> a, FooParameter2 -> b]
a*y^b

Notice the method for extracting the values of the options. The input
options are used first and then the default options.


David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/






From: Steven T. Hatton [mailto:hattons at globalsymmetry.com]
To: mathgroup 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...]?
--
"Philosophy is written in this grand book, The Universe. ... But the book
cannot be understood unless one first learns to comprehend the language...
in which it is written. It is written in the language of mathematics, ...;
without which wanders about in a dark labyrinth."   The Lion of Gaul


  • Prev by Date: Re: serious NDSolve bug?
  • Next by Date: reduced functionality of Solve
  • Previous by thread: Re: Options for my own Packages?
  • Next by thread: Re: Options for my own Packages?