lonewolf
lonewolf

Reputation: 69

Prolog not giving correct answer

I am learning Prolog. I wrote some simple facts. But it seems that Prolog is not giving me right answers. Please help me understand what I am doing wrong here.

facts - weather.pl

weather(pheonix,summer,hot).   
weather(pheonix,winter,warm).  
weather(la,summer,warm).

When I run this in swi-prolog as follows

?- weather(City,_,warm).
City = pheonix .

Result is only shown as pheonix. But la is also warm. Why is it not given as an answer?

Upvotes: 1

Views: 177

Answers (2)

false
false

Reputation: 10102

You need to look at the answer very, very closely:

City = pheonix .
              ^ SPACE!

There is a space between the answer substitution and the dot. This little hint tells us: You have stopped asking for further answers. Try the query again and this time type SPACE or ; but do not type RETURN, for it will again stop the answers.

Upvotes: 2

pasaba por aqui
pasaba por aqui

Reputation: 3519

Typically, after first answer is written, you can type some key, usually ";", to backtrack and receive another answer.

Upvotes: 1

Related Questions