SICStus 3.8.4 (sparc-solaris-5.7): Mon Jun 12 18:41:59 MET DST 2000 Licensed to acrc.bristol.ac.uk | ?-?- is the Prolog prompt at which you can type a query, ended by a period. Prolog programs should be stored in a file and then read into the Prolog interpreter, by means of the query ?-consult(file). (which can be abbreviated ?-[file].). The default extension of a SICStus Prolog file is .pl, so the query ?-consult(file). will either load file or file.pl. If your filename contains non-alphanumeric characters you should use single quotes (e.g. ?-consult('file.txt').). The Prolog file to be used for this chapter's lab exercises is labs1.pl. Copy it to your own directory, then load it into Prolog:
| ?- [labs1]. {consulting /home/public/www/HTML/Teaching/Resources/COMS30106/labs/labs1.pl...} {Warning: [L] - singleton variables in nearby/2 in lines 15-18} {Warning: [L] - singleton variables in reachable/3 in lines 19-22} {Warning: [L] - singleton variables in reachable/3 in lines 22-23} {/home/public/www/HTML/Teaching/Resources/COMS30106/labs/labs1.pl consulted, 10 msec 2448 bytes}Don't worry about the warnings, they concern don't-care variables that occur only once in a clause (sometimes they indicate mis-spelled variable names, however).
| ?- reachable(bond_street,piccadilly_circus,Stations,Lines). Stations = [oxford_circus], Lines = [central,bakerloo] ? ; Stations = [green_park], Lines = [jubilee,piccadilly] ? ; Stations = [green_park,oxford_circus], Lines = [jubilee,victoria,bakerloo] ? ; noNote that a Prolog program is correct only if all the answers it returns are correct, not only the first one! As shown above you can ask for the next answer by pressing ; followed by return.
NB. Don't worry about the duplicate lines that sometimes show up in the list of lines -- we will see later how to deal with them.
This introduces another problem with nearby -- which one?
| ?- stations(Line,Stations). Line = victoria, Stations = [green_park,oxford_circus] ? ; Line = central, Stations = [bond_street,oxford_circus,tottenham_court_road] ? ; Line = jubilee, Stations = [bond_street,green_park,charing_cross] ? ; Line = piccadilly, Stations = [green_park,piccadilly_circus,leicester_square] ? ; Line = bakerloo, Stations = [oxford_circus,piccadilly_circus,charing_cross] ? ; Line = northern, Stations = [tottenham_court_road,leicester_square,charing_cross] ? ; noNB. You'll have to treat the Victoria line separately, as it has only 2 stations.
Can you do something similar for finding all lines a particular station is on? Why not?
line(central,[bond_street,oxford_circus,tottenham_court_road]). line(jubilee,[bond_street,green_park,charing_cross]). line(piccadilly,[green_park,piccadilly_circus,leicester_square]). line(victoria,[green_park,oxford_circus]). line(bakerloo,[oxford_circus,piccadilly_circus,charing_cross]). line(northern,[tottenham_court_road,leicester_square,charing_cross]).and rewrite the definition of connected using this representation.