Task

Pass a function     as an argument     to another function.



Related task

   First-class functions


 
MODULE HOFuns;
IMPORT
  NPCT:Tools,
  Out;
TYPE
  Formatter = PROCEDURE (s: STRING; len: LONGINT): STRING;
VAR
  words: ARRAY 8 OF STRING;
 
  PROCEDURE PrintWords(w: ARRAY OF STRING; format: Formatter);
  VAR
    i: INTEGER;
  BEGIN
    i := 0;
    WHILE (i < LEN(words)) DO
      Out.Object(format(words[i],16));
      INC(i)
    END;
    Out.Ln
  END PrintWords;
BEGIN
  words[0] := "Al-Andalus";
  words[1] := "contributed";
  words[2] := "significantly";
  words[3] := "to";
  words[4] := "the";
  words[5] := "field";
  words[6] := "of";
  words[7] := "medicine";
 
  PrintWords(words,Tools.AdjustLeft);
  PrintWords(words,Tools.AdjustCenter);
  PrintWords(words,Tools.AdjustRight)
END HOFuns.
 