MathGroup Archive 2012

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

Search the Archive

Re: Pattern Syntax for Alternate Heads with Default Value


On Apr 4, 5:28 am, Ben <ben... at gmail.com> wrote:
> 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

Hi Ben
Maybe something like that?

f[x_ (Real | Integer)] := x^2; f[] = 6.25;

(But all Integer are Real, I don't understand the application.
It could be f[x_Real: 2.5] := x^2)
best regards
Murta



  • Prev by Date: Re: how to make formatted output with Grid and Print?
  • Next by Date: Re: How to generate ``nice'' algebra output from command-line mathematica?
  • Previous by thread: Re: Pattern Syntax for Alternate Heads with Default Value
  • Next by thread: Re: Pattern Syntax for Alternate Heads with Default Value