cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Calling a function with fewer parameters than specified in the definition

jstavitsky
1-Newbie

Calling a function with fewer parameters than specified in the definition

Suppose I define a custom function foo with parameters (A,B,C,D) but I want to give the user the option of calling it with only A and B and handling the absence of C and D gracefully in some way. Is it possible to write a test that checks to see if C and D are specified, or will the call return an error in any case where all parameters are not given?

1 ACCEPTED SOLUTION

Accepted Solutions
RichardJ
19-Tanzanite
(To:jstavitsky)

User defined functions with a variable number of parameters are not possible. The only way to come close is to define foo(V), where V is a vector of parameters that could have a variable number of elements.

View solution in original post

3 REPLIES 3
RichardJ
19-Tanzanite
(To:jstavitsky)

User defined functions with a variable number of parameters are not possible. The only way to come close is to define foo(V), where V is a vector of parameters that could have a variable number of elements.

Thanks

Joseph Stavitsky wrote:

Suppose I define a custom function foo with parameters (A,B,C,D) but I want to give the user the option of calling it with only A and B and handling the absence of C and D gracefully in some way. Is it possible to write a test that checks to see if C and D are specified, or will the call return an error in any case where all parameters are not given?

As Richard says, it's not possible to have optional arguments to a function. This capability has been repeatedly asked for since at least Mathcad version 2000.

Stuart

Top Tags