MathGroup Archive 1999

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

Search the Archive

Re: Checking the form of an option

  • To: mathgroup at
  • Subject: [mg21121] Re: Checking the form of an option
  • From: "P.J. Hinton" <paulh at>
  • Date: Fri, 17 Dec 1999 01:21:20 -0500 (EST)
  • Organization: "Wolfram Research, Inc."
  • References: <831k39$>
  • Sender: owner-wri-mathgroup at

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] := 
    optval = MyOptionName /. Flatten[{opts, defaultopts}];
      Message[f::"badopt"] (* message defined by author elsewhere *)

P.J. Hinton
Mathematica Programming Group           paulh at
Wolfram Research, Inc.
Disclaimer: Opinions expressed herein are those of the author alone.

  • Prev by Date: Re: back up for hyperlinks?
  • Next by Date: NonlinearFit: Parameter range not working ??
  • Previous by thread: RE: Checking the form of an option
  • Next by thread: Re: Checking the form of an option