Anonymous recursion: Difference between revisions

Content added Content deleted
(added Ol)
Line 1,592: Line 1,592:
<pre># fib 8;;
<pre># fib 8;;
- : int option = Some 34</pre>
- : int option = Some 34</pre>

=={{header|Ol}}==
This uses named let to create a local function (loop) that only exists inside of function fibonacci.
<lang scheme>
(define (fibonacci n)
(if (> 0 n)
"error: negative argument."
(let loop ((a 1) (b 0) (count n))
(if (= count 0)
b
(loop (+ a b) a (- count 1))))))

(print
(map fibonacci '(1 2 3 4 5 6 7 8 9 10)))
</lang>
{{out}}
<pre>'(1 1 2 3 5 8 13 21 34 55)</pre>


=={{header|OxygenBasic}}==
=={{header|OxygenBasic}}==