Re: Question on defaults in positional arguments
- To: mathgroup at smc.vnet.net
- Subject: [mg112629] Re: Question on defaults in positional arguments
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Thu, 23 Sep 2010 04:23:57 -0400 (EDT)
Handle with two definitions
Clear[f]
f[y_: 2] := f[1, y, 3]
f[x_, y_, z_: 3] := {x, y, z}
{f[], f[y], f[x, y], f[x, y, z]}
{{1, 2, 3}, {1, y, 3}, {x, y, 3}, {x, y, z}}
Bob Hanlon
---- NP <nomplume69 at gmail.com> wrote:
=============
Hi,
I was wondering if there was a way in selectively specifying some of
the arguments of a function (rest remaining default). For instance,
consider
Clear[f, x, y,z];
f[x_: 1, y_: 2,z_:3] := {x, y}
f[5]
{5,2,3}
Here the default values of y and z are automatically used. How can I
call f so that, for example, the default value of x and z are used
instead?
Thanks,
NP