summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ack.kpl16
-rw-r--r--fib.kpl20
-rw-r--r--letter_table.kpl2
-rw-r--r--shared_counter.kpl6
4 files changed, 15 insertions, 29 deletions
diff --git a/ack.kpl b/ack.kpl
index 2161836..bba01ea 100644
--- a/ack.kpl
+++ b/ack.kpl
@@ -1,26 +1,20 @@
// Ackermann function
-`export ack : ([m; n]
- t : `type m;
- ? t != `type n {
- `panic "m and n must be the same type"
- }
- ? |(t = Int_signed; t = Float) {
- ? |(m < 0; n < 0) { `return 0 }
- }
+`export ack : ([I64; I64.m; I64.n]
? {
+ |(m < 0; n < 0) { 0 }
m = 0 { n + 1 }
&(m > 0; n = 0) { ack `sync (m - 1; 1) }
{ ack `sync (m - 1; ack `sync (m; n - 1)) }
}
)
-`export ack_string : ([m; n]
+`export ack_string : ([String; I64.m; I64.n]
"#MAGENTA#ack#(#CYAN#%#, #CYAN#%#) #WHITE#=# #GREEN#%#\n" `format (m; n; ack `sync (m; n))
)
-`is_main ([]
+`is_main ([Void]
`use "sys" [args]
? 4 != `length args {
`return `error String $ (
@@ -28,5 +22,5 @@
"#BOLD#WHITE#Usage: % % <m> <n>#\n" `format (args `get 0; args `get 1)
)
}
- `value ack_string `sync (U64 $ args `get -2; U64 $ args `get -1)
+ `value ack_string `sync (I64 $ args `get -2; I64 $ args `get -1)
)
diff --git a/fib.kpl b/fib.kpl
index debb6f0..bf2d384 100644
--- a/fib.kpl
+++ b/fib.kpl
@@ -1,31 +1,21 @@
/*
Fibonacci sequence
- n can be any numeric type
*/
-`export fib : ([n]
- t : `type n
- ? {
- |(t = Int_signed; t = Float) {
- ? n <= 0 { `return 0 }
- }
- t = Int_unsigned {
- ? n = 0 { `return 0 }
- }
- { `panic "invalid type for n" }
- }
+`export fib : ([I64; I64.n]
? {
+ n = 0 { 0 }
n < 2 { 1 }
{ `sync(fib; n - 1) + fib `sync n - 2 }
}
)
-`export fib_string : ([n]
+`export fib_string : ([String; I64.n]
"#MAGENTA#fib#(#CYAN#%#) #WHITE#=# #GREEN#%#\n" `format (n; fib `sync n)
)
-`is_main ([]
+`is_main ([Void]
`use "sys" [args]
? 3 != `length args {
`return `error String $ (
@@ -33,5 +23,5 @@
"#BOLD#WHITE#Usage: % % <n>#\n" `format (args `get 0; args `get 1)
)
}
- `value fib_string `sync U64 $ args `get -1
+ `value fib_string `sync I64 $ args `get -1
)
diff --git a/letter_table.kpl b/letter_table.kpl
index e80f485..ad447be 100644
--- a/letter_table.kpl
+++ b/letter_table.kpl
@@ -1,7 +1,7 @@
// Read a utf8 string and count all the occurrences of each letter found
-`export letter_table : ([string]
+`export letter_table : ([String.string]
table : Map[Char; U64] $ ()
@ string {[letter]
? table `has letter {
diff --git a/shared_counter.kpl b/shared_counter.kpl
index 0fdf804..01f01bd 100644
--- a/shared_counter.kpl
+++ b/shared_counter.kpl
@@ -3,7 +3,7 @@
counter : %shared 0
-inc_dec : ([amount]
+inc_dec : ([I64.amount]
header : "#BOLD#Thread: %#, #WHITE#Counter:# " `format `thread_id
body : ^ counter {[c]
c +: amount
@@ -19,11 +19,13 @@ inc_dec : ([amount]
inc : inc_dec `bind 1
dec : inc_dec `bind -1
+Inc_Dec_fn `type dec
+
actions : %const 1_000
batch : %const 100
-runner : ([fn]
+runner : ([Inc_Dec_fn.fn]
total : actions
@ total {
`log "#WHITE#Batch: #CYAN#% #MAGENTA#%#\n" `format (fn; total)