I am new to prolog.I want to write compare_lists/2 which will compare 2 lists and return true if they have at least one common element. I know this can be done with something like that
common_list([H|_],T) :- member(H,T).
common_list([_|T],L) :- common_list(T,L).
common_list2(L1,L2) :- member(X,L1),member(X,L2).
but I want to do it without Prolog built-in predicates. I tried writing this
common_elements([H|_],[H|_]).
common_elements(L,[_|T]) :- common_elements(L,T).
common_elements([_|T],L):-common_elements(T,L).
but when I ask the online swish prolog tool common_elements([3,13,8,1],[5,3,7,3,1]).
It answers true 37 times not 3 like the common_list/2 and common_list2/2 (I have to use cut to get only 1 instead of 3 but that's a different story).