length/2 — count the number of elements in a list
Size is unified with the number of elements in
?- length([a,b,c], X). X=3 yes. ?- length([a | T], 3). T=[_A,_B] yes.
length/2 is defined by :
length(List, Length) :- length(List, 0, Length). length(, Length, Length) :- !. length([_ | Rest ], Old, Length) :- New is Old + 1, length(Rest, New, Length).