Fibonacci numbers in Oz
Example for versions
Mozart 1.4.0
This example uses tail-recursive definition of Fibonacci numbers.
functor
import
Application System
define
fun{Fib N}
fun{Loop N A B}
if N == 0 then
B
else
{Loop N-1 A+B A}
end
end
in
{Loop N 1 0}
end
local
S
in
S = {NewCell ""}
for I in 1..16 do
S := {Append {Append @S {Int.toString {Fib I}}} ", "}
end
{System.showInfo {Append @S "..."}}
{Application.exit 0}
end
end
Comments
]]>blog comments powered by Disqus
]]>