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:
- 50,000th Message
- From: "Steven M. Christensen" <steve@smc.vnet.net>
- 50,000th Message