I’m using: SWI-Prolog version 8.1.9.
I couldn’t find a predicate in the SWI-Prolog docs that given two lists, gives you a list of all the elements not shared by the two lists. I wrote my own and would like comments on it. Also, if something already existed and I missed it, please link the relevant docs page to me:
% ----->>>>> gen_disjoint_element_from_lists(+List, +DisjointList, -DisjointElement)
% Description: Generate one element from the given list that is not
% an element of DisjointList.
gen_disjoint_element_from_lists(List, DisjointList, DisjointElement) :-
member(DisjointElement, List),
\+ member(DisjointElement, DisjointList).
% ----->>>>> try_list_1_or_list_2(+List_1, +List_2, -DisjointElement)
% Description: Generate one element from either list that is
% not an element of the other.
try_list_1_or_list_2(List_1, List_2, DisjointElement) :-
gen_disjoint_element_from_lists(List_1, List_2, DisjointElement)
;
gen_disjoint_element_from_lists(List_2, List_1, DisjointElement).
% ----->>>>> disjoint_list(+List_1, +List_2, ?DisjointList)
% Description: Returns the union list of the elements of
% List_1 not found in List_2, and the elements of List_2
% not found in List_1.
disjoint_list(List_1, List_2, DisjointElementsList) :-
findall(
DisjointElement,
try_list_1_or_list_2(List_1, List_2, DisjointElement),
DisjointElementsList).