2
votes

I wrote a program in prolog.

parent(Amy,John).
parent(Bob,John).
parent(John,Ben).
parent(Alice,Ben).

I'm using SWI-Prolog on Ubuntu 12.04. When I insert my file in swi-prolog interpreter:

['example.pl']

I'm getting warnings:

Warning: /home/mazix/example1.pl:1:
        Singleton variables: [Amy,John]
Warning: /home/mazix/example1.pl:2:
        Singleton variables: [Bob,John]
Warning: /home/mazix/example1.pl:3:
        Singleton variables: [John,Ben]
Warning: /home/mazix/example1.pl:4:
        Singleton variables: [Alice,Ben]
% example1.pl compiled 0.00 sec, 4 clauses
true.

What do these mean? And what does the true at the bottom mean? How should I get rid of this warnings?

3

3 Answers

8
votes

Identifiers starting with a capital letter are variables. If you want atoms, enclose them in single quotes:

parent('Amy', 'John').

or start them with a small letter:

parent(amy, john).

A "singleton variable" is a named variable that appears only once in its lexical scope. What this means, in practice, is that you name it, but you don't do anything useful with it, hence the compiler warning.

3
votes

Ahh.. change all your names to lower case john, ben, etc.

Since they are upper case, prolog thinks they are variables. And since you didn't use those variables, it is warning you that you will hit problems later on.

The 'true' just means that it has loaded the module.. with warnings. Everything you do in prolog returns true or false.. no escape from that.

1
votes

You are using uppercase names for your relations, which indicates a variable. You should get aware of the different datatypes in Prolog. Boris already gave you the hint.

Singleton variables tells you that you are not using this variable anywhere else. true at the end tells you, that there is no contradiction in your prolog rules (because there are no rules anyhow).