This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
vsc e5f4633c39 This commit was generated by cvs2svn to compensate for changes in r4,
which included commits to RCS files with non-trunk default branches.


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@5 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2001-04-09 19:54:03 +00:00

35 lines
802 B
Plaintext

/*
**********************************************************************
*
* CLP(R) Version 2.0 (Example Programs Release)
* (C) Copyright, March 1986, Monash University
*
**********************************************************************
*/
%
% Simple recursive formulation of fibonacci numbers.
% The goal ?- go shows how the definition can be used for
% both finding a a fibonacci number given its index, and finding the index
% of a given fibonacci number.
%
fib(0, 1).
fib(1, 1).
fib(N, X1 + X2) :-
N > 1,
fib(N - 1, X1),
fib(N - 2, X2).
go:- fib(10, Z),
printf("forward: fib(10) = %d\n",[Z]),
fib(Y, Z),
printf("backward: fib(%d) = %d\n",[Y,Z]).
% Answer:
% forward: fib(10) = 89
% backward: fib(10) = 89
?- printf("\n>>> Sample goal: go/0\n", []).