length(List, Length) :- ( var(Length) -> length(List, 0, Length) ; Length >= 0, length1(List, Length) ). length([], Length, Length). length([_|L], N, Length) :- N1 is N+1, length(L, N1, Length). length1([], 0) :- !. length1([_|L], Length) :- N1 is Length-1, length1(L, N1).The following should be noted:
1. This predicate does not perform any type testing functions.
2. This predicate is not protected by ECLiPSe and may be redefined without generating a warning message.
Success: length([1,2,3],N). (gives N=3). length([1,2,1,X],N). (gives X=_g84; N=4). length(L,2). (gives L=[_g62,_g72]). % creates list Fail: length([1,2,3],2).