:-module fibonacci.
:-interface.
:-import_module io.

:-pred main(io, io).
:-mode main(di, uo) is det.

:-func fibonacci(int)= int.

:-implementation.
:-import_module int, list, string.

main(!IO) :-
    command_line_arguments(Args, !IO),
    (if Args = [Arg|_] then
	    Number = det_to_int(Arg),
	    format("Fibonacci number of %d is %d\n", 
			   [ i(Number), i(fibonacci(Number)) ], 
			   !IO)
    else 
	    true
    ).

fibonacci(Number)=  
    (if Number < 2 then 
	    1
    else 
	    fibonacci(Number - 1) + fibonacci(Number - 2)
    ).