Lab 1 notes: Getting started with Prolog ------------------------------- We use SWI Prolog (Tell the students that there are versions for all platforms, they can follow the link on the course webpage). In the lab there is SWI Prolog for Windows. Using SWI Prolog. ----------------- Start Prolog: pl or, in Windows, start SWI-Prolog/Prolog from menu (AllPrograms). To load (or "consult") a file called file.pl use one of the following: - in Windows, use the Menu option File/Consult ?- consult('file.pl'). ?- consult(file). ?- ['file.pl']. ?- [file]. To define some predicates without having to first save them to file, consult "user": ?- [user]. ... type your predicates ... ^D It's a good idea, however, to get in the habit of using files most of the time, because what you type here will be lost as soon as you exit Prolog. ?- listing. % lists all the user-defined predicates currently loaded % Getting help in SWI Prolog. ?- help(Topic). or ?- apropos(Word). To exit pl use one of the following: ?- halt. ?- Ctrl-D Very simple example: ------------------- % this is the file likes.pl % this is a comment: likes(X,Y) means X likes Y likes(john, mary). likes(mary, jim). likes(emily, john). likes(mary, ed). likes(ed, emily). ?- [likes]. like compiled, 0.00 sec, 1,076 bytes. Yes ?- likes(john, mary). Yes ?- likes(john,X). X = mary ?- likes(mary,X). X = jim ; X = ed ; No ?- likes(X,Y). X = john Y = mary ; X = mary Y = jim ; X = emily Y = john ; X = mary Y = ed ; X = ed Y = emily ; No /* run queries such as: Does john like mary, who does mary like, who likes who. */ --------------- More complex example: Consult the file family.pl available on the course webpage under Lab1. Study it and run various queries. Develop the following predicates: sister, brother, aunt, uncle, nephew, niece, cousin, second_cousin, etc.