(* The Great Win32 Language Shootout http://dada.perl.it/shootout/

   contributed by Isaac Gouy (Modula2 novice)

   To build: xc =m ackermann
   To run:     ackermann 8
*)

MODULE Ackermann;

(* Prefer unqualified procedure import *)
FROM LanguageShootout IMPORT N;

FROM STextIO IMPORT WriteString, WriteLn;
FROM SWholeIO IMPORT WriteCard;


PROCEDURE Ack (m, n: CARDINAL) : CARDINAL;
BEGIN
   IF m=0 THEN RETURN n+1; END;
   IF n=0 THEN RETURN Ack(m-1, 1); END;
   RETURN Ack(m-1, Ack(m, n-1));
END Ack;


VAR n: CARDINAL;

BEGIN
  n := N();

  WriteString("Ack(3," ); WriteCard(n,1); WriteString("): ");
  WriteCard( Ack(3,n), 1); WriteLn;
END Ackermann.