MathGroup Archive 2006

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

Search the Archive

RE: Programming with options.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68078] RE: [mg68037] Programming with options.
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 21 Jul 2006 17:36:36 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

MaxArt,

You can do it this way:

Options[Pow] = {Exponent -> 2};
Pow[a, opts___?OptionQ] :=
  Module[{e},
    e = Exponent /. {opts} /. Options[Pow];
    a^e
    ]

{Pow[a], Pow[a, Exponent -> 3]}
{a^2, a^3}

With a good email address you will get a quicker personal reply.

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


From: MaxArt [mailto:maxart.yZEROSPAM at tiscali.it]
To: mathgroup at smc.vnet.net


Hi,
I want to create some new functions in Mathematica (4.0), and I want it to
work with options like Plot and other graphic functions. The idea behind
this is to modify the result and the behaviour of my functions when extra
arguments are given, and I thought that the use of options would be perfect.
For example, if I want to create a function Pow that gives the square of a
number, except when an option Exponent is given, so that Pow[a, Exponent ->
3] yields a^3.

How can I do that?

MaxArt




  • Prev by Date: Re: Reasonable integration speed? (24 hrs and counting)
  • Next by Date: Re: Applying a list of 2D paramters to a mathematica function
  • Previous by thread: Re: Programming with options.
  • Next by thread: Re: Programming with options.