% fib.pro :- initialization(main). add(X, Y, Z) :- Z is (X + Y). fib(N, [1,1|Fib3]) :- append(Fib1, [_], Fib2), append(Fib2, [_], Fib3), length([1,1|Fib3], N), maplist(add, [1,1|Fib1], [1|Fib2], Fib3), !. puts(N) :- format("~d~n", [N]). main :- current_prolog_flag(argv, [_,Length|_]), number_atom(N, Length), fib(N, F), maplist(puts, F), halt.
Build.
$ gplc fib.pro
Run.
$ ./fib 10 1 1 2 3 5 8 13 21 34 55