Setting up for Prolog |
/opt/local/bin
, so you will
have to put that location in your path using the following steps.cd
to your home directory.vi .profile
PATH=/opt/local/bin:$PATH
export PATH
vi
,
the standard Unix text editor, for writing your Prolog programs.
There are many beginning tutorials online.
Here
is a summary of the vi commands.?
, you have three options:;
to compute the next solutiona
to compute all remaining solutions<ret>
to stop the executionStan-Warfords-iMac:prolog warford$ gprolog GNU Prolog 1.4.0 By Daniel Diaz Copyright (C) 1999-2011 Daniel Diaz | ?- consult( 'fig1_8.pl'). compiling /Users/warford/Documents/Classes/cs450/prolog/fig1_8.pl for byte code... /Users/warford/Documents/Classes/cs450/prolog/fig1_8.pl compiled, 46 lines read - 3223 bytes written, 18 ms (1 ms) yes | ?- parent( bob, pat). yes | ?- parent( liz, pat). no | ?- parent( X, liz). X = tom ? a no | ?- parent( X, Y). X = pam Y = bob ? ; X = tom Y = bob ? ; X = tom Y = liz ? ; X = bob Y = ann ? a X = bob Y = pat X = pat Y = jim yes | ?- halt.You exit gprolog with the
halt.
gprolog
programs not followed by our book.
All clauses must be contiguous on the head of the clause.
Thus, the program fragment from the book
female( pam). % Pam is female male( tom). % Tom is male male( bob). female( liz). female( ann). female( pat). male( jim).must be written
female( pam). % Pam is female female( liz). female( ann). female( pat). male( tom). % Tom is male male( bob). male( jim).Also, the
different
predicate
is not supplied in our version of prolog. Define different
with two rules as follows (see page 125):
different( X, X) :- !,fail. different( _, _).The cut operator
!
prevents the second rule from executing
after the first rule fails. You should include these two rules in
all files that use the predicate different
.