MathGroup Archive 2004

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

Search the Archive

Re: Functions with optional parameters


Gregory Lypny wrote:
> 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.

Hi Greg,

Here is code I copied from the Mathematica 5.0.1 Help Browser, which I 
got from looking up BlankNullSequence (___).

In[1]:=
f[x_,y___]:=x+y

In[2]:=
f[a,b,c,d]

Out[2]=
a+b+c+d

In[3]:=
f[a]

Out[3]=
a

-- 
Curt Fischer


  • Prev by Date: Re: Re: Garbage collection problem
  • Next by Date: Re: Counting Runs
  • Previous by thread: Re: Functions with optional parameters
  • Next by thread: Re: Functions with optional parameters