Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Functions with optional parameters

  • To: mathgroup at
  • Subject: [mg51955] Re: [mg51886] Functions with optional parameters
  • From: Bob Hanlon <hanlonr at>
  • Date: Fri, 5 Nov 2004 02:19:26 -0500 (EST)
  • Reply-to: hanlonr at
  • Sender: owner-wri-mathgroup at

addThem[a__] := Plus[a];


a + b + c


a + b

f1[x_,y_,z_] :=g[x,y,z];
f1[x_,y_]:= h[x,y];


g[a, b, c]


h[a, b]

To assign a default value

f2[x_,y_,z_:d] := g[x,y,z];


g[a, b, c]


g[a, b, d]

Bob Hanlon

> From: Gregory Lypny <gregory.lypny at>
To: mathgroup at
> Date: 2004/11/04 Thu AM 01:49:57 EST
> To: mathgroup at
> Subject: [mg51955] [mg51886] Functions with optional parameters
> Hello everyone,
> How can I create functions with optional parameters?  For example, a 
> simple function to add two or three numbers:
> addThem[a_,b_,c_]:=If[c is not empty, Sum[a,b,c],Sum[a,b]]
> I'm not sure of the proper syntax to test whether c is null or empty.
> 	Greg

  • Prev by Date: Re: Functions with optional parameters
  • Next by Date: Re: Re: Plotting scattergram
  • Previous by thread: Re: Functions with optional parameters
  • Next by thread: foreach loop