I'm writing a function called subseq which checks if one list is a subsequence of another.
subseq([],[]).
subseq([],[Y|Ys]).
subseq([X|Xs],[Y|Ys]) :- X=:=Y, subseq(Xs,Ys).
subseq([X|Xs],[Y|Ys]) :- X=\=Y, subseq([X|Xs],Ys).
When I try subseq(X,[1,2]) I get:
X = [] ? ;
uncaught exception: error(instantiation_error,(=:=)/2)
Why is this happening? My guess is that [] is being operated on by =:=, but how do I check for/prevent this error?