diff options
Diffstat (limited to 'ack.kpl')
| -rw-r--r-- | ack.kpl | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -2,19 +2,23 @@ // Ackermann function `export ack : Fn[m; n] $ ( - ? !=(`type m; `type n) { - `panic "m and n must be the same type" + t : `type m; + ? |(t != `type n; t != Int[Any; Any; Any]) { + `panic "m and n must be the same type of Int" + } + ? t = Int[Any; .signed; Any] { + ? |(m < 0; n < 0) { `return 0 } } ? { m = 0 { n + 1 } - &(m > 0; n = 0) { ack `call_sync (m - 1; 1) } - &(m > 0; n > 0) { ack `call_sync (m - 1; ack `call_sync (m; n - 1)) } + &(m > 0; n = 0) { ack `sync (m - 1; 1) } + &(m > 0; n > 0) { ack `sync (m - 1; ack `sync (m; n - 1)) } { 0 } } ) `export ack_string : Fn[m; n] $ ( - String $ ("ack("; m; " "; n; ") = "; ack `call_sync (m; n); "\n") + String $ ("ack("; m; " "; n; ") = "; ack `sync (m; n); "\n") ) `is_main Fn $ ( @@ -25,5 +29,5 @@ "Usage: "; args `get 0; " "; args `get 1; " <m> <n>\n" ) } - `print ack_string `call_sync (I64 $ args `get -2; I64 $ args `get -1) + `print ack_string `sync (I64 $ args `get -2; I64 $ args `get -1) ) |
