Top
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

Syntax:
apply( expression , function );
Purpose:
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.
Example:
 
proc p(int x) {return(x^2);}
intvec v=1,2,3;
apply(v,p);
==> 1 4 9
intvec vv=apply(v,p);vv;
==> 1,4,9
list ll=apply(v,p);ll;
==> [1]:
==>    1
==> [2]:
==>    4
==> [3]:
==>    9


Top 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
            User manual for Singular version 4-0-3, 2016, generated by texi2html.