scope # Ackermann function proc ackermann( m :: number, n :: number ) :: number feature reminisce; # create a remember table for this procedure # it seems the procedure must be global for this statement return if m = 0 then n + 1 elif m = 1 then n + 2 # expand some cases to avoid more elif m = 2 then 3 + 2 * n # recursion - as in the Maple elif m = 3 then 5 + 8 * ( 2 ^ n - 1 ) # Mathematica, etc. samples elif n = 0 then ackermann( m - 1, 1 ) else ackermann( m - 1, ackermann( m, n - 1 ) ) fi end; local constant fmt := seq( " %1.0f", " %2.0f", " %2.0f", " %2.0f" , " %3.0f", " %3.0f", " %3.0f", " %4.0f" , " %4.0f", " %4.0f", " %4.0f", " %5.0f" , " %5.0f", " %5.0f", " %6.0f", " %6.0f" , " %6.0f", " %7.0f", " %7.0f", " %7.0f" , " %7.0f", " %7.0f", " %7.0f", " %7.0f" ); local constant maxN := 20; printf( " n" ); for n from 0 to maxN do printf( fmt[ n + 1 ], n ) od; print(); printf( " m+" ); for n from 0 to 18 do printf( "------", n ) od; print(); for m from 0 to 3 do printf( "%2d|", m ); for n from 0 to maxN do printf( fmt[ n + 1 ], ackermann( m, n ) ) od; print() od end