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: [mg125841] Re: Pattern Syntax for Alternate Heads with Default Value
  • From: "djmpark" <djmpark at comcast.net>
  • Date: Thu, 5 Apr 2012 05:43:58 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <10944665.56141.1333528611484.JavaMail.root@m06>

f[x : (_Real | _Integer) : 2.5] := x^2 

The general form is name:pattern:default.


David Park
djmpark at comcast.net 
http://home.comcast.net/~djmpark/index.html 


From: Ben [mailto: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: Bug in pattern test, or I did something wrong?
  • Next by Date: Re: Pattern Syntax for Alternate Heads with Default Value
  • Previous by thread: Re: Pattern Syntax for Alternate Heads with Default Value
  • Next by thread: Re: Pattern Syntax for Alternate Heads with Default Value