summary refs log tree commit diff
path: root/examples/fib.ccl
diff options
context:
space:
mode:
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