Acker.mesa
Copyright Ó 1984, 1987 by Xerox Corporation. All rights reserved.
Russ Atkinson (RRA) May 18, 1987 4:13:12 pm PDT
DIRECTORY
BasicTime;
Acker: CEDAR PROGRAM IMPORTS BasicTime = BEGIN
depth: INT ← 0;
maxDepth: INT ← 0;
calls: INT ← 0;
useStats: BOOL = TRUE;
Ack: PROC [x, y: INT] RETURNS [ans: INT] = {
IF useStats THEN {
calls ← calls + 1;
depth ← depth + 1;
IF depth > maxDepth THEN maxDepth ← depth;
};
SELECT TRUE FROM
x = 0 => ans ← 1;
y = 0 => ans ← IF x = 1 THEN 2 ELSE x+2;
ENDCASE => ans ← Ack[Ack[x-1, y], y-1];
IF useStats THEN
depth ← depth - 1;
};
Test: PROC [x: INT] RETURNS [INT, REAL] = {
pulses: BasicTime.Pulses = BasicTime.GetClockPulses[];
z: INT = Ack[x, 2];
time: REAL = BasicTime.PulsesToSeconds[BasicTime.GetClockPulses[] - pulses];
RETURN [z, time];
};
Loop: PROC [x, times: INT] RETURNS [INT, REAL] = {
pulses: BasicTime.Pulses = BasicTime.GetClockPulses[];
z: INT;
time: REAL;
THROUGH [0..times) DO
z ← Ack[x, 2];
ENDLOOP;
time ← BasicTime.PulsesToSeconds[BasicTime.GetClockPulses[] - pulses];
RETURN [z, time];
};
END.