Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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 smc.vnet.net
  • Subject: [mg50018] Re: Optional Alternatives
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Thu, 12 Aug 2004 05:43:23 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <200408101002.GAA19525@smc.vnet.net> <cfcqsn$45f$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

f[Optional[x : (_Real | _Rational), 0.0]] := {Head[x], x}

??

Regards
  Jens

Selwyn Hollis wrote:
> 
> 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
> http://www.appliedsymbols.com
> (edit reply-to to reply)


  • References:
  • Prev by Date: Re: how to graphically fill the tails of a normal distribution
  • Next by Date: Re: message 50001?
  • Previous by thread: Re: Optional Alternatives
  • Next by thread: Re: How to set linewidth in 3-D graphics?