arguments
keyword to check function arguments
Arguments block must be the expression in the function.
Syntax
arguments argName1 (dimensions) datatype {validators} = defaultValue ... argNameN end
Arguments
- argName1, ... argNameN
Name of the arguments from function protoptype.
All input arguments must be declared in
arguments
block and in the same order.- (dimension)
Expected (i, j, ...) dimensions for an input argument like
(2, 3, 4)
. Must be a list of integer values or:
or input variable name.Matrix form (4, [3 6 10]) can be used to except size of
4 x 3
or4 x 6
or4 x 10
.If input argument is a scalar and expected dimensions are bigger, input argument will be expand to match the expected dimensions.
If expected dimensions is a vector (1xn or nx1) and input argument is a vector, input will be transposed to match expected form.
- datatype
Expected datatype of input arguments. Inputs must be of datatype or convertable to this type.
datatype
can bedouble
,(u)int(8/16/32/64)
,boolean
,string
.- {validators}
List of predefined functions used to check input validity.
Each validator must be validate to accept the input.
- defaultValue
If an input is not given by caller, variable will take this value.
All variables with default value must be at the end of the prototype.
Examples
function test(x, y) arguments x (1, 10) double {mustBeReal, mustBePositive} y double = 1 end disp(x, y) end
//OK a = 1:10; test(a) //y == 1 its default value test(a') //x will be transposed to match 1 x 10 dimensions, y == 1 test(42, 2) //x become a(ones(1, 10)) and y == 2
//rejected test() //x is required test(a, list(1)) // a list cannot be convert to a double test(0:9) // x must be > 0
See also
- Arguments validators — List of predefined validators that can be used in arguments block.
History
バージョン | 記述 |
2024.0 | Introduction in Scilab. |
Report an issue | ||
<< abort | Control flow | Arguments Validators >> |