这是我的代码:-
fib(0,0).
fib(1,1).
fib(F,N) :-
N>1,
N1 is N-1,
N2 is N-2,
F is F1+F2,
fib(F1,N1),
fib(F2,N2),
write(F," ,").
在咨询 GNU Prolog 时,我得到:
| ?- consult('C:/GNU-Prolog/bin/fib.pl').
compiling C:/GNU-Prolog/bin/fib.pl for byte code...
C:/GNU-Prolog/bin/fib.pl compiled, 3 lines read - 1253 bytes written, 15 ms
yes
| ?- fib(F,2).
uncaught exception: error(instantiation_error,(is)/2)