|
[Date Index]
[Thread Index]
[Author Index]
Re: Optional Alternatives
- To: mathgroup at smc.vnet.net
- Subject: [mg50036] Re: Optional Alternatives
- From: Bill Rowe <readnewsciv at earthlink.net>
- Date: Thu, 12 Aug 2004 05:44:00 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 8/11/04 at 5:53 AM, sh2.7183 at misspelled.erthlink.net (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
The only way I know to achieve this is as follows:
f[x_Real]:=x
f[x_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
The following might do for you
In[1]:= g[x_, s_:0] := x + s
In[2]:= g[2]
Out[2]= 2
In[3]:= g[2, 2]
Out[3]= 4
--
To reply via email subtract one hundred and four
Prev by Date:
Re: Re: How to set linewidth in 3-D graphics?
Next by Date:
Re: How to set linewidth in 3-D graphics?
Previous by thread:
SE and CI in NonlinearRegress
Next by thread:
Re: Optional Alternatives
|