MathGroup Archive 2010

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

Search the Archive

Re: Default and head in function argument

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111623] Re: Default and head in function argument
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Sat, 7 Aug 2010 06:22:58 -0400 (EDT)

Hi,

Clear[f];
f[x : (_Integer?Positive) : 3] := x^3


Regards,
Leonid


On Sat, Aug 7, 2010 at 9:31 AM, NP <nomplume69 at gmail.com> 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: Convex Hull again
  • Next by Date: Re: parallel computing and message disabling
  • Previous by thread: Default and head in function argument
  • Next by thread: Re: Default and head in function argument