MathGroup Archive 1999

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

Search the Archive

RE: Re: Checking the form of an option

  • To: mathgroup at
  • Subject: [mg21239] RE: [mg21219] Re: [mg20982] Checking the form of an option
  • From: "Ersek, Ted R" <ErsekTR at>
  • Date: Mon, 20 Dec 1999 02:27:59 -0500 (EST)
  • Sender: owner-wri-mathgroup at

John Ross 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.
>There are many ways to approach this.
>I write a toy example that does what you want.
Thank you. This helps a lot. May I add an additional question related both
to this one and to one I asked previously and to which Andrzej Kozlowski
responded? If I have a function NonComplexQ[x_]  which returns True if x is
a non-complex numeric, then how can I use *this* in your suggestions about
checking options. They appear to rely on a particular Head rather than a
predicate. Is there a neat way of moving over to the predicate form and
checking whether I have an option which is a single NonComplex numeric or a
list of NonComplex numerics?

I modify my previous example to do what you want.  I throw in an extra case
to see if K is greater than one.  In that case I use the pure function
(#>1&).  If this notation is foreign to you look up Slot, SlotSequence at my

As before the last pattern in Switch is (_) which matches anything. You only
get the that pattern if the other two fail.

Options[f] = {K -> 2};

f[x_, opts___] :=
  {k1 = K /. Flatten[{opts, Options[f]}]},
    _?(#>1&), (k1, "K is greater than one.")
    _?NonComplexQ, {k1, "K is numeric and not complex."},
    {__?NonComplexQ}, {k1, "K is a list of numeric, non-complex values."},
    _, {k1, "K is not a non-complex numeric or list of non-complex

For anyone who missed the earlier discussion, NonComplexQ is a function that
several of us gave definitions for earlier. 

Ted Ersek

For Mathematica tips, tricks see

  • Prev by Date: Re: GraphicsArray and alignment of graphs
  • Next by Date: Re: GraphicsArray and alignment of graphs
  • Previous by thread: Re: Checking the form of an option
  • Next by thread: Laplace transforms in version 4