[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to get some statements about a constant?

From: Sean Charles
Subject: Re: how to get some statements about a constant?
Date: Sat, 12 Oct 2013 15:42:20 +0100

On 12 Oct 2013, at 14:02, liubin0314 <address@hidden> wrote:

such as:
KB is:
does prolog can get the answer to X(baba,wo) which is father(baba,wo)?

and x(Y,wo)?

| ?- listing.

aunt(gugu, wo).
father(baba, wo).

| ?- X(baba,wo).
uncaught exception: error(syntax_error('user_input:4 (char:2) . or operator expected after _expression_'),read_term/3)
| ?- x(Y,wo).
uncaught exception: error(existence_error(procedure,x/2),top_level/0)
| ?- 
It's actually not a bad question, at least not to me because I can't answer it as well as I'd like. I have been using Prolog in earnest for about five months every day and I think I know what I am doing but a question like this can catch you out!

Your first question about "X(baba,wo)" shows that you may not have grasped the way you ask questions of Prolog in general which is fine if you are just starting out. If you want facts that state who is the father you should (as you have) have this:

    father(baba, wo).

but then you would phrase the question like this:

    father(baba, X).

I hope now you can begin to see that you are thinking "the wrong way around" at least when it comes to expressing your facts about whom is the father of who. That question will cause prolog to scan the database for facts that match and there is only one.

Hope that helps.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]