|
[Date Index]
[Thread Index]
[Author Index]
Re: Default and head in function argument
- To: mathgroup at smc.vnet.net
- Subject: [mg111643] Re: Default and head in function argument
- From: "Scot T. Martin" <smartin at seas.harvard.edu>
- Date: Sun, 8 Aug 2010 07:23:31 -0400 (EDT)
I believe that you're after:
f[x:_Integer?(Positive):3] := x^3
The important point is the use of "(...)" to keep Mathematica oriented
about your intentions.
On Sat, 7 Aug 2010, NP wrote:
> Hi,
>
> I know how to define a function so that it evaluates only when the
> head of the argument is of a certain type:
>
> Clear[f];
> f[x_Integer?Positive] := x^3
> f[3]
> f[3.1]
> f[-3]
>
> 27
> f[3.1]
> f[-3]
>
> and I also know how to set default to an argument of a function like
> so:
>
> Clear[f]
> f[x_:3]
> f[]
>
> 27
>
> How do I do both i.e., specify head and default value?
>
> Thanks,
>
> NP
>
>
Prev by Date:
problem with calling Mathematica from a Web application in ASP .NET
Next by Date:
Re: Rearrange equation II
Previous by thread:
Re: Default and head in function argument
Next by thread:
Re: Default and head in function argument
|