dos_compilers/Digital Research PLI-86 v1/ACKTST.PLI
2024-06-30 12:01:25 -07:00

45 lines
1.3 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/************************************************/
/* This program tests the STKSIZ function while */
/* evaluating a RECURSIVE procedure. */
/************************************************/
ack:
procedure options(main,stack(2000));
declare
(m,n) fixed,
(maxm,maxn) fixed,
ncalls decimal(6),
(curstack, stacksize) fixed,
stksiz entry returns(fixed);
put skip list('Type max m,n: ');
get list(maxm,maxn);
do m = 0 to maxm;
do n = 0 to maxn;
ncalls = 0;
curstack = 0;
stacksize = 0;
put edit('Ack(',m,',',n,')=',ackermann(m,n),
ncalls,' Calls,',stacksize,' Stack Bytes')
(skip,a,2(f(2),a),f(6),f(7),a,f(4),a);
end;
end;
stop;
ackermann:
procedure(m,n) returns(fixed) recursive;
declare
(m,n) fixed;
ncalls = ncalls + 1;
curstack = stksiz();
if curstack > stacksize then
stacksize = curstack;
if m = 0 then
return(n+1);
if n = 0 then
return(ackermann(m-1,1));
return(ackermann(m-1,ackermann(m,n-1)));
end ackermann;
end ack;