Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9421 > unrolled thread
| Started by | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| First post | 2012-04-05 09:46 +0000 |
| Last post | 2012-04-05 09:46 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Pattern Syntax for Alternate Heads with Default Value Bob Hanlon <hanlonr357@gmail.com> - 2012-04-05 09:46 +0000
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Date | 2012-04-05 09:46 +0000 |
| Subject | Re: Pattern Syntax for Alternate Heads with Default Value |
| Message-ID | <jljpmf$cma$1@smc.vnet.net> |
Clear[f]
f[x_Real: 2.5] = x^2;
f[x_Integer] = x^2;
{f[3], f[1.5], f[], f[I]}
{9, 2.25, 6.25, f[I]}
Clear[f]
f[] = 6.25;
f[x_Real | x_Integer] = x^2;
{f[3], f[1.5], f[], f[I]}
{9, 2.25, 6.25, f[I]}
Bob Hanlon
On Wed, Apr 4, 2012 at 4:27 AM, Ben <benp84@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
>
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web