Re: Checking the form of an option
- To: mathgroup at smc.vnet.net
- Subject: [mg21121] Re: Checking the form of an option
- From: "P.J. Hinton" <paulh at wolfram.com>
- Date: Fri, 17 Dec 1999 01:21:20 -0500 (EST)
- Organization: "Wolfram Research, Inc."
- References: <831k39$dju@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 12 Dec 1999, DIAMOND Mark wrote: > I want to check whether option "K" to a function is an integer, a list of > single numbers, or neither of these, and then to execute one of three > different statements. > > If these K were a simple parameter, I could do it with > f[k_Integer] := functionBody; > f[k:{_Integer}..] := functionBody; > f[k_] := functionBody > > but I cannot see how to check for similar conditions on an *option* inside > one function. Can anyone help? Normally, options are not checked as part of the pattern for the left-hand side of a rule. Rather, they are checked in the body of the function. f[k_, opts___?OptionQ] := Module[ <snip!> optval = MyOptionName /. Flatten[{opts, defaultopts}]; If[Not[IntegerQ[optval]], Message[f::"badopt"] (* message defined by author elsewhere *) ] <snip!> ] -- P.J. Hinton Mathematica Programming Group paulh at wolfram.com Wolfram Research, Inc. Disclaimer: Opinions expressed herein are those of the author alone.