Skip to main content
1-Visitor
Mar 11, 2015 11:03 PM UTC
Solved

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?

RichardJAnswer
19-Tanzanite
Mar 11, 2015 11:53 PM UTC

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.

3 replies

RichardJ19-TanzaniteAnswer
19-Tanzanite
Mar 11, 2015 11:53 PM UTC

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.

Translate
1-Visitor
Mar 12, 2015 7:54 PM UTC

Thanks

Translate
23-Emerald V
Mar 12, 2015 7:18 PM UTC

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

Translate