BinProlog 3.30 Copyright (C) Paul Tarau 1992-1994
by FTP from: clement.info.umoncton.ca
E-MAIL to : binprolog@info.umoncton.ca
(C-ified standalone)
(with C-interface)
Finished loading system C-code (21310 instructions).
Finished loading user C-code (4 instructions).
?-
1.2 To log prolog session from unix shell:
>script
>bp
.... continue using prolog
... as soon as you exit prolog enter this:
>exit
Now the log is in a file named 'typescript' in the current directory.
2. To exit prolog type control-D:
?- ^D
Prolog execution halted(0). CPU time = 0.20s
3. Three ways to add facts and rules after starting prolog:
3.1 Load a pre-existing program:
?- consult('ex1.pro'). /* read in my prolog program */
% using compile/1 is MUCH faster
consulting(ex1.pro)
consulted(ex1.pro,time(0))
yes
?- cat(morris).
yes
?- cat(mickey).
no
3.2 Use assert for each fact or rule:
?- assert(parent(gbush,wbush)).
yes
?- parent(X,Y).
X=gbush,
Y=wbush;
3.3 Input from keyboard by typing [user]:
?- [user].
compiling(to(mem),user,...)
female(rosemary).
parent(jimmy,amy).
parent(rosemary,amy).
male(jimmy).
female(rosemary,A) :-
true(A).
father(X,Y) :- parent(X,Y),male(X).
mother(X,Y) :- parent(X,Y),female(X).
/* now type control-d to end input from keyboard */
^D
bytes_used(code(232),strings(56),symbols(40),htable(108),total(436))
compile_time(10)
?- father(X,amy).
X=jimmy;
no
?- mother(rosemary,X).
X=amy;
no
4. Sample prolog session:
> bp
BinProlog 3.30 Copyright (C) Paul Tarau 1992-1994
by FTP from: clement.info.umoncton.ca
E-MAIL to : binprolog@info.umoncton.ca
(C-ified standalone)
(with C-interface)
Finished loading system C-code (21310 instructions).
Finished loading user C-code (4 instructions).
?- consult('ex1.pro'). /* read in my prolog program */
% using compile/1 is MUCH faster
consulting(ex1.pro)
consulted(ex1.pro,time(0))
yes
?- cat(morris).
yes
?- cat(mickey).
no
?- cat(X).
X=garfield;
X=morris;
X=fluffy;
no
/* note that above I typed ';' to get all bindings of X */
?- loves(X,fluffy).
X=garfield;
no
?- loves(garfield,Z).
Z=fluffy;
no
?- loves(X,Z).
X=garfield,
Z=fluffy;
no
?- chases(X,Y).
X=garfield,
Y=mickey;
X=garfield,
Y=minney;
X=morris,
Y=mickey;
X=morris,
Y=minney;
X=fluffy,
Y=mickey;
X=fluffy,
Y=minney;
no
?- mouse(minney).
yes
/* now type ^D to escape */
?- ^D
Prolog execution halted(0). CPU time = 0.50s
5. Example of file containing simple Prolog program:
/* File: ex1.pro
* Example of a simple Prolog program
*/
/* basic facts: */
cat(garfield). /* one-place predicate */
cat(morris).
mouse(mickey).
cat(fluffy).
female(fluffy).
lovable(tweety).
likes(garfield, morris). /* 2-place predicate */
/* rules: */
chases(X,Y) :- cat(X), mouse(Y).
mouse(minney) :- true. /* this rule always succeeds */
loves(garfield, Y) :-
cat(Y),
female(Y).