summaryrefslogtreecommitdiff
path: root/fib.kpl
diff options
context:
space:
mode:
Diffstat (limited to 'fib.kpl')
-rw-r--r--fib.kpl20
1 files changed, 5 insertions, 15 deletions
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
)