users-prolog
[Top][All Lists]
Advanced

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

Re: General question about better documentation and specific question


From: Salvador Abreu
Subject: Re: General question about better documentation and specific question
Date: Sun, 2 Dec 2001 09:42:48 +0000

On Sat, 1 Dec 2001 19:05:56 -0800 (PST)
Violetta Cavalli-Sforza <address@hidden> wrote:

> not(P) :- P, !, fail ; true.

Just use the \+ built-in (eg as an operator).  It does this already.

> can_marry(X,Y) :- X \= Y, not(sibling(X,Y)), not(cousin(X,Y)).

... however, negation (this includes the \= and the "not"s) under
regular Prolog cannot produce bindings, so, for this to work, you'd have
to make X and Y ground before can_marry/2 can be of any use.

What's happening is that X \= Y is failing right away (as will the
negations, when you reorder the goals...)

One possible way of doing this is by defining a predicate person/1 which
could be set up as follows:

person(X) :- father(X, _).
person(X) :- father(_, X).
person(X) :- mother(X, _).
person(X) :- mother(_, X).

your clause for can_marry/2 could then become:

can_marry(X, Y) :-
        person(X), person(Y),
        X \= Y,
        \+ sibling(X, Y),
        \+ cousin(X, Y).

This predicate will certainly generate repeated solutions (because of
the definition for person/1) but it should behave better.

BTW, this kind of issue is best discussed in the comp.lang.prolog
newsgroup...

Regards
Salvador



reply via email to

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