|
[Date Index]
[Thread Index]
[Author Index]
Re: Functions with optional parameters
- To: mathgroup at smc.vnet.net
- Subject: [mg51929] Re: Functions with optional parameters
- From: Curt Fischer <crf3 at po.cwru.edu>
- Date: Fri, 5 Nov 2004 02:17:34 -0500 (EST)
- References: <cmclfa$i7s$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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
|