home—lectures—recipe—exams—hws—D2L—breeze (snow day)
lect35-prolog-basics
prolog intro
tutorials: www.learnprolognow.com
www.amzi.com/AdventureInProlog
You can also run jlog, a web interpreter: see hints on Running JLog
We saw already:
- run /usr/local/bin/xsb from rucs
- facts vs rules
-
To load a file family.P from the xsb prompt, type:
[family].
warning:
Don't have spaces in your filename.
(That's maybe not too unsurprising: xsb interprets that as a list of length two.)
Also, don't have hyphens in your filename!;
xsb interprets the hyphens as subtraction, and gives a syntax error.
-
a standard family-tree example: 'father(X,Y) :- male(X), parent(X,Y).'
-
Self-exercise: grandfather, w/ a partner.
(What is the def'n in English, for "Old is a grandparent of Yng"?)
-
talk/reflect about how this is declarative programming
(just saying 'prolog searches for all solutions', without saying more);
-
write a recursive rule: 'ancestor'.
-
have them take a crack at writing with a partner:
-
nth-father (generalized grandfather; call 'ancestor')
-
sameLastName (or, “sameYChromosone”): check for male-only lineage
-
Write cousin.
-
Digress, in English:
cousin, 2nd cousin, 3rd cousin;
nth cousin m times removed.
-
Write nthCousin (which detects exact nth-cousins, 0 times removed)
-
Remember facts just rules w/o variables;
no intrinsic difference inside prolog.
-
Helpful tips:
trace,
and see http://www.cs.toronto.edu/~joanis/324/w01/xsbprolog.txt.
home—lectures—recipe—exams—hws—D2L—breeze (snow day)