MathGroup Archive 2004

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

Search the Archive

Re: Functions with optional parameters


Hi,

a)
addThem[a_, b_, c_:Undefined] := If[Undefined === c, a + b, a + b + c]

b)

addThem[a__] := Plus[a]

Regards
  Jens

"Gregory Lypny" <gregory.lypny at videotron.ca> schrieb im Newsbeitrag 
news:cmclfa$i7s$1 at smc.vnet.net...
> 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: foreach loop
  • Next by Date: Re: Counting Runs
  • Previous by thread: Re: Functions with optional parameters
  • Next by thread: Re: Functions with optional parameters