I need to know how to compare the length of two lists in Prolog. This is what I have so far:
sum(N1,N2) :-
checklength(N1,N2).
checklength(N1,N2) :-
L1 is length(N1,What),
L2 is length(N2,What),
Comp(L1,L2).
Comp(L1,L2) :-
L1=:=L2.
Of course, the answer from CapelliC is perfect, but you can try also the "standard" method of approaching this problem:
you can use unification:
this will succeed only if N1 and N2 have the same length.
Btw
L1 is length(N1,What)
doesn't make sense. length/2 is a predicate, not a function. That is, it will succeed or fail, but doesn't 'return' a value. Otoh, is/2 expects an arithmetic expression as right operand.edit
If you're using SWI-Prolog, then you can simply use
same_length/2
predicate.