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