We are now working on a textbook for Grace, tentatively titled “Programming with Grace”. A draft of the book as well as information about both built-in libraries and graphics and animation libraries are also available on the site. We expect to put more information to help people learn how to program in Grace.
Month: June 2014
The Ackermann Function
Apropos of nothing, here’s a Grace version of Ackermann’s Function inspired by Sam Tobin-Hochstadt’s Racket example:
123456 method ack (m:Number, n:Number) -> Number {print "ack {m} {n}"if (m ≤ 0) then { n + 1 }elseif {n ≤ 0} then { ack((m-1), 1) }else { ack(m-1, ack(m, n-1)) }}
One interesting thing to note is that the condition after elseif is in {braces}, while the conditions after if is in (parens). This makes logical sense — because the first condition is always evaluated — but is of course inconsistent with every other condition. (Apologies for the fixed-width font.)