Task

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




BEGIN
 
    ! APPLIES A CALLBACK FUNCTION TO AN ARRAY ;
    PROCEDURE APPLY(ARR, FUN);
        REAL ARRAY ARR;
        PROCEDURE FUN IS REAL PROCEDURE FUN(X); REAL X;;
    BEGIN
        INTEGER I;
        FOR I := LOWERBOUND(ARR, 1) STEP 1 UNTIL UPPERBOUND(ARR, 1) DO
            ARR(I) := FUN(ARR(I));
    END APPLY;
 
    ! CALLBACK ;
    REAL PROCEDURE SQUARE(X); REAL X; SQUARE := X * X;
 
    REAL ARRAY A(1:5);
    INTEGER I;
    FOR I := 1 STEP 1 UNTIL 5 DO A(I) := I;
    APPLY(A, SQUARE);
    FOR I := 1 STEP 1 UNTIL 5 DO OUTFIX(A(I), 2, 8); OUTIMAGE;
 
END.