Skip to content
Discussion options

You must be logged in to vote

This can be done with disjunction and negation.

A(x) :- x in [1,2,3,4];
B(x) :- x in [2,3,4,5];

Difference(x) :- (A(x), ~B(x)) | (B(x), ~A(x));

You can add more info to the result to simplify debugging:

A(x) :- x in [1,2,3,4];
B(x) :- x in [2,3,4,5];

Difference(x, reason:) :- 
  (A(x), ~B(x), reason == "A but not B") |
  (B(x), ~A(x), reason == "B but not A");

Note that here the difference is taken for a predicate over 1 argument.
It would work the same way if you repeat a few arguments.

Taking difference of full rows would require some more work.

If the goal is to unit-test the program, it could be more productive to set up a testing framework and test in with a simple text diff.
A nic…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tkawachi
Comment options

Answer selected by tkawachi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants