Search code examples
prologsingleton

Prolog "Not together in source file" and "Singleton Variable" errors


I am new to prolog and have made a simple prolog program, i keep getting theses errors, there are more but i didnt think all off them would be needed as they are all the same:

    Clauses of door/2 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:27:
      Clauses of room/1 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:28:
    Clauses of door/2 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:34:
    Clauses of location/2 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:36:
    Clauses of location/3 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:37:
    Clauses of location/2 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:38:
    Clauses of location/3 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:40:
    Clauses of location/2 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:42:
    Clauses of location/3 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:49:
    Clauses of location/2 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:51:
    Singleton variables: [North,Table]
Warning: c:/users/hani cassidy/desktop/test/test.pl:51:
    Clauses of location/3 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:52:
    Singleton variables: [East,Table]
Warning: c:/users/hani cassidy/desktop/test/test.pl:53:
    Singleton variables: [South,Table]
Warning: c:/users/hani cassidy/desktop/test/test.pl:54:
    Singleton variables: [Table] 
Warning: c:/users/hani cassidy/desktop/test/test.pl:55:
    Singleton variables: [Centre,Table]
ERROR: c:/users/hani cassidy/desktop/test/test.pl:59:20: Syntax error: Operator expected
Warning: c:/users/hani cassidy/desktop/test/test.pl:67:

I noticed that they are all the same so i know it will be the same mistake on each one however i just cant work out what as i am new to prolog, A Section of my code is below: door(hall, bedroomA). door(hall, bedroomB). door(hall, sittingroomkitchen).

%Bedroom B – Hall
room(bedroomB).
door(bedroomB, hall).

%Sitting room / Kitchen – Hall, Bathroom
room(sittingroomkitchen).
door(sittingroomkitchen, hall).
door(sittingroomkitchen, bathroom).

%Bathroom – Sitting room/Kitchen
room(bathroom).
door(bathroom, sittingroomkitchen).

%Each Bedroom = Desk, Bed, Pillow, Duvet, Wardrobe
location(bed, bedroomA).
location(pillow, bed, bedroomA).
location(duvet, bed, bedroomA).
location(wardrobe, bedroomA).
location(desk, bedroomA).
location(phone, underPillow, bedroomA).
location(bed, bedroomB).
location(pillow, bed, bedroomB).

If any more is needed i can provide, this is just a snippet.


Solution

  • Regarding the "Clauses of ... are not together in the source-file" warnings, most (if not all) Prolog systems expect clauses for the same predicate to be together in a source file. The solution is to either add discontiguous/1 directives for the predicates whose clauses are scattered in the source file OR to move all their clauses together. For the first solution write, before any clauses for those predicates:

    :- discontiguous([
        room/1, door/2, location/2, location/3
    ]).
    

    Discontiguous predicates sometimes are due to typos in code (e.g. accidentally forgetting an argument in a clause head) and should never be ignored.