interstar
interstar

Reputation: 27166

Prolog : find something not referenced in another predicate

Suppose I have a db

p1(red). 
p1(green).

p2(green).

How do I find all the things that are in p1 but not in p2 (ie. red)

Upvotes: 3

Views: 43

Answers (1)

false
false

Reputation: 10102

How do I find all the things that are in p1 but not in p2 (ie. red)

In this particular simple case, it suffices to ask:

?- p1(X), \+ p2(X).
   X = red
;  false.

However, this scheme cannot be extended easily for more complex programs. A lot of semantic issues would have to be resolved. Like ...

... non-monotonicity. When you add the fact p2(red), the query will fail. So this program is inherently non-monotonic.

... insufficient instantiation. This happens when the terms are more complex and not ground.

... inconsistency. This happens when you want to use constrains like CLP(FD) at the same time in your program. Unexpected failure of \+ p2(X) might be a consequence.

Upvotes: 4

Related Questions