Reputation: 13
mergelist([],[],[]).
mergelist([X],[],[X]).
mergelist([],[Y],[Y]).
I'm running this query ?-mergelist([1],[],[1]).
which returns true
But then I run this query ?-mergelist([1,2],[],[1,2]).
it returns false(no).
I'm not sure what's wrong.
I'm using ECLiPSe 6.1
Upvotes: 0
Views: 95
Reputation: 56
Prolog can't pattern match [1,2] with any of:
[X] is specifically designed to pattern match with a one-element list.
Try this:
mergelist(L,[],L) :- is_list(L).
mergelist([],L,L) :- is_list(L).
Upvotes: 3