Home > Archive > Prolog > May 2007 > Newbie question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| patrick.sannes@gmail.com 2007-05-17, 7:06 pm |
| Hi there,
I'm just starting with prolog and I have a newbie question.
Why is this code correct (and ok, not in an ethical way;-))
woman(mia).
woman(ines).
man(vincent).
relation(vincent,X) :- woman(X).
And this code not
woman(mia).
woman(ines).
man(vincent).
relation(vincent,woman(X)).
Hope someone can explain it to me....
Patrick
| |
|
| <patrick.sannes@gmail.com> wrote in message
news:1179413612.452997.17320@q23g2000hsg.googlegroups.com...
> Hi there,
> I'm just starting with prolog and I have a newbie question.
== DISCLAIMER ==
I'm also a prolog newbie (worst : I've not open any Prolog app. for 4 years)
but I'll try to answer, with my poor words.
Please keep in mind that I may be completely wrong, using wrong words or
wrong concepts, etc. :)
================
> Why is this code correct (and ok, not in an ethical way;-))
> woman(mia).
> woman(ines).
> man(vincent).
> relation(vincent,X) :- woman(X).
You're specifying the following rule : vincent has a relation with X if
woman(X) is true.
Though I may envy vincent (do I really ? damn, this man MUST be tired at the
end of the day !) I don't see any (Prolog) problem here.
> And this code not
> woman(mia).
> woman(ines).
> man(vincent).
> relation(vincent,woman(X)).
Here you're specifying a simple fact : relation(vincent, woman(X)) is
always true.
I know what you meant : you wanted to rule that vincent has a relation with
X whenever X is a woman, but your fact is slightly different. You're not
telling Prolog that woman(X) has to be true for the relation with vincent to
happen.
Let me explain my point.
woman(X) may be true (that's specifically the case for X=mia or ines); it
may also be false (say X=vincent). Your rule doesn't take the value of
'woman' into account.
For example :
relation(vincent,woman(mia)) is true.
relation(vincent, woman(vincent)) is also true...
relation(vincent, woman(the_devil_himself)) goes the same.
So if you request Prolog to solve relation(vincent, woman(X)), any value for
X is valid, because this is a FACT of your database.
If you're trying to solve relation(vincent,Y), Prolog unifies
relation(vincent,Y) with your fact, and therefore Y to woman(X). As any
value of X is ok to evaluate woman(X) (no matter whether it evaluates to
true or false), Prolog should tell you that Y=woman(ANY_VALUE).
In a less formal way, just try to consider the plain english translation of
your rule :
You meant that vincent has a relation with X if X is a woman.
Or you just wrote that vincent has a relation with the fact that X is (or
isn't) a woman.
I don't know if anybody has relations with facts nowadays, but I'd rather a
good (not too) old human being.
> Hope someone can explain it to me....
Hope it helps a bit.
-- W. ( In space, no-one can hear you scream.
Dans les embouteillages parisiens non plus d'ailleurs
mais c'est pas pour la même raison... )
| |
| Matthew Huntbach 2007-05-18, 4:18 am |
|
On Thu, 17 May 2007, patrick.sannes@gmail.com wrote:
> Hi there,
>
> I'm just starting with prolog and I have a newbie question.
>
> Why is this code correct (and ok, not in an ethical way;-))
> woman(mia).
> woman(ines).
> man(vincent).
> relation(vincent,X) :- woman(X).
>
> And this code not
>
> woman(mia).
> woman(ines).
> man(vincent).
> relation(vincent,woman(X)).
>
> Hope someone can explain it to me....
>
> Patrick
>
Common newbie problem - confusing functional with relational programming.
In your second example, in relation(vincent,woman(X)) the expression
woman(X) has no relationship to the predicate given by the two rules
woman(mia) and woman(ines). Prolog doesn't have the concept of calls
embedded in calls. What look like calls within calls, as in your second
woman(X) are just tagged tuples, they do not initiate any computation.
Matthew Huntbach
|
|
|
|
|