module builtint. type length list A -> int -> o. type countup int -> list int -> int -> o. type nth int -> list A -> A -> o. length nil 0. length (X::L) N1 :- length L N, N1 is N + 1. countup N nil M :- N > M, !. countup N (N::nil) N :- !. countup N (N::L) M :- N1 is N + 1, countup N1 L M. nth N L X :- N < 1, !, fail. nth 1 (X::L) X :- !. nth N (X::L) Y :- N1 is N - 1, nth N1 L Y.