Thursday, October 20, 2005

Prolog - Lecture 1

Prolog:
  • Two types of statements:
    • Rules
    • Propositions
  • File extension: .pl (just like Perl)
  • Periods end statements.
  • Avoid using spaces in code with the "gprolog" interpreter/compiler (GNU Prolog 1.2.16).
  • This compiler is very user-unfriendly.
  • Capital letters are "variables".
  • At the interpreter prompt, type "[X]." to load and compile a file named X.pl. Do not type "[X.pl].".
  • Type "trace." to enable trace mode, which will display the steps done by the interpreter.
  • Type "notrace." to turn off trace mode.
With this file:
likes(jake,chocolate).
likes(jake,apricots).
likes(darcie,licorice).
likes(darcie,apricots).

Output of "likes(X,chocolate).":
X = jake ? ; (it waits for command here:
; to show next solution, a for all solutions, to stop)
no

comma (",") is an "and" operator.
Output of "likes(darcie,X),likes(jake,X).":
X = apricots
yes

----
grandmother(X,Y):-mother(X,Z),mother(Z,Y).
grandmother(X,Y):-mother(X,Z),father(Z,Y).
mother(anna,peter).
mother(anna,clara).
mother(mary,anna).
father(joe,peter).
father(jim,clara).
father(tom,joe).

The "grandmother" statements are a propositions. ":-" means "implies".

grandmother(X,peter).
X = mary ? ;
no

0 Comments:

Post a Comment

<< Home