This is a sample session with the CLP( ) system. Some extra information is given using comments after the % character.
% clpr CLP(R) Version 1.2 (c) Copyright International Business Machines Corporation 1989 (1991) All Rights Reserved 1 ?- f(X,Y) = f(g(A),B). % some simple ``unification'' B = Y X = g(A) *** Yes 2 ?- X = Y + 4 , Y = Z - 3, Z = 2. % simple arithmetic evaluation Z = 2 Y = -1 X = 3 *** Yes 3 ?- X + Y < Z, 3 * X - 4 * Y = 4, 3 * X + 2 * Y = 1. Y = -0.5 X = 0.666667 0.166667 < Z *** Yes 4 ?- X + Y < Z, 3 * X - 4 * Y = 4, 2 * X + 3 * Z = 1. Y = -1.125*Z - 0.625 X = -1.5*Z + 0.5 -0.0344828 < Z *** Yes 5 ?- history. 1 f(X, Y) = f(g(A), B). 2 X = Y + 4, Y = Z - 3, Z = 2. 3 X + Y < Z, 3 * X - 4 * Y = 4, 3 * X + 2 * Y = 1. 4 X + Y < Z, 3 * X - 4 * Y = 4, 2 * X + 3 * Z = 1. *** Yes 6 ?- 2. % run second goal again X = Y + 4, Y = Z - 3, Z = 2. Z = 2 Y = -1 X = 3 *** Yes 7 ?- ['examples/fib']. % consult (load) a program >>> Sample goal: go/0 *** Yes 8 ?- ls fib. % look at the program fib(0, 1). fib(1, 1). fib(N, X1 + X2):- N > 1, fib(N - 1, X1), fib(N - 2, X2). *** Yes 9 ?- fib(5,F). % only one answer to this F = 8 *** Retry?; *** No 10 ?- F > 7, F < 9, fib(N,F). % only ask for the first answer N = 5 F = 8 *** Retry? 11 ?- [`'examples/mortgage']. % use "`" to reconsult >>> Sample goals: go1/0, go2/0 *** Yes 12 ?- ls. % look at the entire rulebase h:- history. fib(0, 1). fib(1, 1). fib(N, X1 + X2):- N > 1, fib(N - 1, X1), fib(N - 2, X2). go:- printf(\nFib(14) = , []), ztime, fib(14, X), ctime(T1), printf(% (Time = %)\n, [X, T1]), printf(Fib-1(610) = , []), ztime, fib(Y, 610), ctime(T2), printf(% (Time = %)\n, [Y, T2]). mg(P, T, I, B, MP):- T = 1, B = P + P * I - MP. mg(P, T, I, B, MP):- T > 1, mg(P * (1 + I) - MP, T - 1, I, B, MP). go1:- ztime, mg(999999, 360, 0.01, 0, M), ctime(T), printf(Time = %, M = %\n, [T, M]). go2:- ztime, mg(P, 720, 0.01, B, M), ctime(T), printf(Time = %\n, [T]), dump([P, B, M]). *** Yes 13 ?- [`'examples/mortgage']. Warning: mg/5 has been redefined >>> Sample goals: go1/0, go2/0 *** Yes 14 ?- ls. h:- history. fib(0, 1). fib(1, 1). fib(N, X1 + X2):- N > 1, fib(N - 1, X1), fib(N - 2, X2). go:- printf(\nFib(14) = , []), ztime, fib(14, X), ctime(T1), printf(% (Time = %)\n, [X, T1]), printf(Fib-1(610) = , []), ztime, fib(Y, 610), ctime(T2), printf(% (Time = %)\n, [Y, T2]). mg(P, T, I, B, MP):- T = 1, B = P + P * I - MP. mg(P, T, I, B, MP):- T > 1, mg(P * (1 + I) - MP, T - 1, I, B, MP). go1:- ztime, mg(999999, 360, 0.01, 0, M), ctime(T), printf(Time = %, M = %\n, [T, M]). go2:- ztime, mg(P, 720, 0.01, B, M), ctime(T), printf(Time = %\n, [T]), dump([P, B, M]). *** Yes 15 ?- go2. Time = 0.25 M = -7.74367e-06*B + 0.0100077*P *** Retry? 16 ?- [user]. p(X) :- writeln(X). ^D *** Yes 17 ?- p(hello). hello *** Yes