Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: Pattern Syntax for Alternate Heads with Default Value

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125854] Re: Pattern Syntax for Alternate Heads with Default Value
  • From: Adriano Pascoletti <adriano.pascoletti at uniud.it>
  • Date: Thu, 5 Apr 2012 05:48:30 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • 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 at 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
>
>


  • Prev by Date: Re: Pattern Syntax for Alternate Heads with Default Value
  • Next by Date: Re: how to make formatted output with Grid and Print?
  • Previous by thread: Pattern Syntax for Alternate Heads with Default Value
  • Next by thread: Re: Pattern Syntax for Alternate Heads with Default Value