I am trying to implement a list difference routine in prolog. For some reason the following fails:
difference(Xs,Ys,D) :- difference(Xs,Ys,[],D).
difference([],_,A,D) :- D is A, !.
difference([X|Xs],Ys,A,D) :-
not(member(X,Ys)),
A1 is [X|A],
difference(Xs,Ys,A1,D).
When trying:
?- difference([1,2],[],D).
I get this error:
ERROR: '.'/2: Type error: `[]' expected, found `1' ("x" must hold one character)
^ Exception: (10) _L161 is [2|1] ?