Task

Take a combined set of elements and apply a function to each element.




 
module Main;
type
	Callback = procedure (integer): integer;
	Vector = array {math} * of integer;
 
procedure Power(i:integer):integer;
begin
	return i*i;
end Power;
 
procedure Map(x: Vector;p: Callback): Vector;
var
	i: integer;
	r: Vector;
begin
	r := new Vector(len(x));
	for i := 0 to len(x) - 1 do	
		r[i] := p(i);
	end;
	return r
end Map;
 
procedure Write(x: Vector);
var
	i: integer;
begin
	for i := 0 to len(x) - 1 do
		write(x[i]:4)
	end;
	writeln
end Write;
 
var
	x,y: Vector;
 
begin
	x := [1,2,3,4,5];
	Write(Map(x,Power))
end Main.
 