loop
Syntax
loop(func, args...)
or
func:U(args…)
or
func:U X
or
X func:U Y
Arguments
func is a function.
args/X/Y are the required parameters of func.
Details
The loop template is very similar to the each
template. Their difference is about the data form and data type of the function call
results.
-
For the
eachtemplate, the data types and forms of the return value are determined by each calculation result. It returns a vector or matrix if all calculation results have the same data type and form, otherwise it returns a tuple. -
The
looptemplate always returns a tuple.
Examples
Use a matrix as the input.
m=matrix([1 3 4 2,1 2 2 1])
max:U(m)
// output: (4,2)
n=matrix([11 5 9 2,8 5 3 2])
m add:U n
// output: ([12,8,13,4],[9,7,5,3])
Use an array vector as the input.
a=array(INT[], 0, 10).append!([1 2 3, 4 5 4, 6 7 8, 1 9 10]);
sum:U(a)
// output: (6,9,21,19)
Use loop to convert a vector to a tuple.
a=[1,2,3,4,5]
asis:U(a)
// output: (1,2,3,4,5)
