I am working on a function that accepts two sets and returns an intersection of them. However, I dont want to use member function in my code. Here’s the member function :
member( X, [ X | T ] ).
member( X, [ _ | T ] ) :- member( X, T ).
Here’s what I have so far:
set_int(_,[],_).
set_int([H|T],[H|T1],[H|T2]) :-
set_int(T,T1,T2).
set_int(T,[X|T1],T2) :-
set_int(T,T1,T2).
Please help me with my logic.
I think you can dispose of member (or equivalent) only if your sets are ordered. With such assumption, we can compare just heads: