Re: Pattern Syntax for Alternate Heads with Default Value

• To: mathgroup at smc.vnet.net
• Subject: [mg125878] Re: Pattern Syntax for Alternate Heads with Default Value
• From: Christoph Lhotka <christoph.lhotka at fundp.ac.be>
• Date: Thu, 5 Apr 2012 05:56:53 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <201204040827.EAA29886@smc.vnet.net>

```hi,

f[(x_Real | x_Integer) : 2.5] := x^2;
where f[3] = 9
and f[1.5] = 2.25
and f[] = 6.25

I would separate the definitions like

f[] := 6.25
f[x_Real] := x^2
f[x_Integer] := x^2

to get from

{f[], f[3], f[2.25], f[x]}

the results

{6.25, 9, 5.0625, f[x]}.

best,

christoph

On 04/04/2012 10:27 AM, Ben 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
>
>
>

```

• Prev by Date: Re: Printing Notebooks without Input/Output cells
• Next by Date: Specify TransformationFunctions in Simplify[] gives wrong result
• Previous by thread: Re: Pattern Syntax for Alternate Heads with Default Value
• Next by thread: Re: Pattern Syntax for Alternate Heads with Default Value