Fibonacci numbers in POP-11

Example for versions Poplog 15.5 (POP-11)

This example uses recursive definition of Fibonacci numbers and works in the same way as factorial example, except for that loop returns a string which contains a concatenation of all Fibonacci numbers up to n-th.

define fibonacci(n);
    if n < 3 
        then 1
        else fibonacci(n - 1) + fibonacci(n - 2)
    endif
enddefine;

define loop(n);
    if n>1 
        then loop(n-1) >< ', ' >< fibonacci(n)
        else fibonacci(n)
    endif;
enddefine;

loop(16) >< ', ...' =>