Home Online Manual
Back: Control structures
Forward: break
FastBack: Functions
FastForward: System variables
Up: Control structures
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

5.2.1 apply

apply( expression , function );
applies the function to all elements of the first argument. The first argument must be of type intvec, intmat, or list. The result will be an expression list, its type and format will be set by the following assign. The function must be a kernel command or a procedure which takes one argument and returns a a value.
proc p(int x) {return(x^2);}
intvec v=1,2,3;
==> 1 4 9
intvec vv=apply(v,p);vv;
==> 1,4,9
list ll=apply(v,p);ll;
==> [1]:
==>    1
==> [2]:
==>    4
==> [3]:
==>    9