Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9430
| From | Adriano Pascoletti <adriano.pascoletti@uniud.it> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Pattern Syntax for Alternate Heads with Default Value |
| Date | 2012-04-05 09:52 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jljq03$cs8$1@smc.vnet.net> (permalink) |
| References | <201204040827.EAA29886@smc.vnet.net> |
In[1]:= f[x : _Real | _Integer : 2.5] := x^2; In[2]:= f[3] Out[2]= 9 In[3]:= f[1.5] Out[3]= 2.25 In[4]:= f[] Out[4]= 6.25 Adriano Pascoletti 2012/4/4 Ben <benp84@gmail.com> > I'm trying to build a unary function which accepts only arguments with > two possible heads and has a default value. That is, something like > the following, except that this doesn't work. Anyone know how to do > this correctly? > > f[(x_Real | x_Integer) : 2.5] := x^2; > where f[3] = 9 > and f[1.5] = 2.25 > and f[] = 6.25 > >
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Pattern Syntax for Alternate Heads with Default Value Adriano Pascoletti <adriano.pascoletti@uniud.it> - 2012-04-05 09:52 +0000
csiph-web