0

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.

false
  • 10,264
  • 13
  • 101
  • 209
  • 1
    "Singleton variable" means you haven't used the variable anywhere else in the predicate clause. It's a little bit like the "variable was assigned but never used" or "potential use of variable before assignment" warning in other languages. For the other warning, see http://stackoverflow.com/questions/16373927/prolog-clauses-are-not-together-in-source-file. – lurker Jan 05 '15 at 19:10
  • So it doesn't actually affect my program with the way it functions ? –  Jan 05 '15 at 19:15
  • 1
    They might. Singleton variable is either a bug, typographical error, or you intentionally left a variable unused. You need to examine it just like you would any warning from any other compiler. If it was intentional, then it should work fine. The interleaved predicates/facts are also going to work OK (although not best practice in Prolog) as long as the order of any given predicate is per your designed logic. – lurker Jan 05 '15 at 19:19
  • Ahh okay thanks, but is my code that i have shown correct ? –  Jan 05 '15 at 19:36
  • The code does look syntactically correct, but there's no way to tell if the code you show is really correct because (1) you haven't explained what it is supposed to do, and (2) not enough of your code is showing. Also, it's not a well-formed question for stackoverflow.com. Your questions should continue to be specific about certain errors, or about why you aren't getting an expected result. You should look at the stackoverflow.com [Tour](http://stackoverflow.com/tour) and [Help Center](http://stackoverflow.com/help). – lurker Jan 05 '15 at 19:39

2 Answers2

1

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.

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
0

If you have a problem like that then try to compose all same predicates as one after another.

For example ;

You should write like this

female(pam).
female(liz).
female(pat).
female(ann).
male(jim).
male(tom).
male(bob).

instead of

`female(pam).
 female(liz).
 male(jim).
 female(ann).
 male(tom).
 female(pat).
 male(bob).`

Notice that order is not same for both.

Same predicates are passed one after another.