Fibonacci numbers in Erlang

Example for versions erl 5.7.3

This example uses iterative definition of Fibonacci numbers, expressed as tail recursion (each number is calculated only once).

-module(prog).
 
-export([main/0]).
 
fib(1,_,Res) -> 
    io:format("~B, ",[Res]);
fib(N,Prev,Res) when N > 1 -> 
    io:format("~B, ",[Res]),
    fib(N-1, Res, Res+Prev).
 
main() -> 
    fib(16,0,1),
    io:format("...~n").