about summary refs log tree commit diff
path: root/examples/fib.ccl
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2025-03-26 20:22:14 +0300
committerNakidai <nakidai@disroot.org>2025-03-26 20:22:14 +0300
commit6fa64679e24b2bef4aee49657df1b2f411b18392 (patch)
tree9a0a34ec741e24dc8ee80231c71fa5baaed02f78 /examples/fib.ccl
parentec7a100bd2b528ebc467993fc289bdbbe97dc57e (diff)
download3cl-6fa64679e24b2bef4aee49657df1b2f411b18392.tar.gz
3cl-6fa64679e24b2bef4aee49657df1b2f411b18392.zip
Add examples as tests
Diffstat (limited to 'examples/fib.ccl')
-rw-r--r--examples/fib.ccl20
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/fib.ccl b/examples/fib.ccl
new file mode 100644
index 0000000..1a2ae68
--- /dev/null
+++ b/examples/fib.ccl
@@ -0,0 +1,20 @@
+/ Takes an index in the fibonacci sequence on the stack
+/ Returns a number of the fibonacci sequence with a given index
+F {
+    / Let us define some local variables
+    &a &b &c
+
+    / If index is zero or one then we just return the number
+    ?c #; $c+ = c
+    ?c #;
+
+    / Otherwise we get previous two numbers of the sequence
+    / and return their sum
+    = c $c $c
+    - @F = a
+    -- @F = b
+    $a $b*
+}
+
+^+++++++++++++++++++++++=t$t
+$t@F