Fibonacci: Prolog vs. CLP(R)
fib(0,0).
fib(1,1).
fib(N,F) :-
N > 1, N1 is N-1, N2 is N-2, fib(N1,F1), fib(N2,F2),
F is F1 + F2.
fib(10,L)?
fib(N,55)?
// instantiation error
fib(0,0).
fib(1,1).
fib(N,F1 + F2) :-
N > 1, fib(N-1,F1), fib(N-2,F2).
fib(10,L)?
fib(N,55)?
fib(X,X)? //0,1,5
Previous slide
Next slide
Back to first slide
View graphic version