Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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 smc.vnet.net
  • Subject: [mg51961] Re: [mg51886] Functions with optional parameters
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Fri, 5 Nov 2004 02:19:50 -0500 (EST)
  • References: <200411040649.BAA18109@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I'm not sure I get your question. If a, b, c, are numbers, then c cannot be 
empty.. It may be zero. Of course, if they are numbers, you may simply use
In[13]:=
addThem[a_, b_, c_] := Plus @@ {a, b, c}

and it doesn't matter whether c is zero or not. In this problem, it is - 
IMO - unnecesary to define the function addThem, since it takes the same 
amount of typing as simply Plus@@. If you wish to use optional parameters in 
other situations, take a look at the Help browser under Optional.

Tomas Garza

Mexico City

----- Original Message ----- 
From: "Gregory Lypny" <gregory.lypny at videotron.ca>
To: mathgroup at smc.vnet.net
Subject: [mg51961] [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: Counting Runs
  • Next by Date: Re: covariance, eigenvalues
  • Previous by thread: Functions with optional parameters
  • Next by thread: Re: Functions with optional parameters