Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Optional Alternatives

  • To: mathgroup at
  • Subject: [mg50047] Re: [mg50010] Optional Alternatives
  • From: Bob Hanlon <hanlonr at>
  • Date: Fri, 13 Aug 2004 05:55:40 -0400 (EDT)
  • Reply-to: hanlonr at
  • Sender: owner-wri-mathgroup at

The default value must be consistent with your Condition, that is, its Head 
must be Real or Rational






{f[2], 2., 1/2, f[x]}

Bob Hanlon

> From: Selwyn Hollis <sh2.7183 at>
To: mathgroup at
> Date: 2004/08/11 Wed AM 05:53:08 EDT
> To: mathgroup at
> Subject: [mg50047] [mg50010] Optional Alternatives
> Is it possible to require a function argument to match alternative 
> patterns and be optional at the same time? As a toy example, suppose I 
> define
>     f[x:_Real|_Rational]:= x
> Is there a way make the argument optional with a given default value, 
> say 0? I've tried this:
>     f[Optional[x:_Real|_Rational, 0]]:= x
> and various other combinations with no success. (Of course I could do 
> this: f[]:= 0, but I'm interested in the more general issue.)
> -----
> Selwyn Hollis
> (edit reply-to to reply)

  • Prev by Date: How does a notebook get its own filename or directory?
  • Next by Date: Re: Re: Re: How to set linewidth in 3-D graphics?
  • Previous by thread: Re: Optional Alternatives
  • Next by thread: Smalest enclosing circle