From 390503adc3035b18b0c97f22f40f107521817397 Mon Sep 17 00:00:00 2001 From: nodist Date: Tue, 19 May 2026 15:45:59 -0400 Subject: type checking --- ack.kpl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'ack.kpl') diff --git a/ack.kpl b/ack.kpl index 1eb7694..f27af3e 100644 --- a/ack.kpl +++ b/ack.kpl @@ -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; " \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) ) -- cgit v1.2.3