Prolog Confusion

This is a discussion on Prolog Confusion within the Tech Board forums, part of the Community Boards category; I have the following Prolog program. Code: male(jim). male(pat). male(bob). female(alice). female(diane). single(jim). single(pat). single(alice). married(bob). married(diane). parent(bob,jim). parent(bob,pat). parent(bob,alice). ...

  1. #1
    Anirban Ghosh
    Join Date
    Jan 2006
    Posts
    277

    Prolog Confusion

    I have the following Prolog program.

    Code:
    male(jim).
    male(pat).
    male(bob).
    female(alice).
    female(diane).
    
    single(jim).
    single(pat).
    single(alice).
    
    married(bob).
    married(diane).
    
    parent(bob,jim).
    parent(bob,pat).
    parent(bob,alice).
    parent(diane,jim).
    parent(diane,pat).
    parent(diane,alice).
    
    mother(X,Y) :- female(X), parent(X,Y).
    father(X,Y) :- male(X),   parent(X,Y).
    
    siblings(X,Y) :- mother(M,X), mother(M,Y), father(F,X), father(F,Y).
    brother(X,Y)  :- siblings(X,Y), male(X), X \= Y.
    sister(X,Y)   :- siblings(X,Y), female(X), X \= Y.
    When I run the query
    Code:
    sister(alice,jim)
    it prints true and waits for input from user. I expected to print true and exit.

    Code:
    sister(alice,jim).
    true ;
    false.
    Any solution to this problem please.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    This doesn't solve your problem, but shouldn't X \= Y be part of siblings/2, instead of being repeated in brother/2 and sister/2?

    Anyway, whether the program exits or waits for input sounds like it would depend more on your Prolog environment than on the specific program.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Prolog
    By ssharish2005 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-16-2008, 09:54 AM
  2. Prolog
    By YankeePride13 in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-15-2005, 02:50 PM
  3. Prolog
    By xErath in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-05-2004, 08:19 PM
  4. more prolog
    By bob20 in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 12-10-2002, 09:33 PM
  5. Prolog
    By bob20 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 12-03-2002, 06:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21