%first element of a list %first(F,L). %first(F,[F|L]). %?-first(0,[1,2,3]). %----------------------- %is an element a member of a list %member(X,[X|L]). %member(X,[F|L]):-member(X,L). %?-member(3,[1,2,3]). %----------------------- %is the given argument is a list %list([]). %list([X|L]):-list(L). %?-list([]). %----------------------- %is N the length of L %length(0,[]). %length(N,[_|L]):-length(M,L),N is M+1. %?-length(4,[1,2,3,4]). %----------------------- %is the given element the last of the list %last(F,[F|[]]). %last(F,[X|T]):-last(F,T). %?-last(1,[3,2,1]). %----------------------- %is the given element before the last one in the list %beforelast(F,[F,A|[]]). %beforelast(F,[_|T]):- beforelast(F,T). %?-beforelast(1,[3,2,1,0]). %----------------------- %is the given element X, the N-th in the list L %nelement(X,N,L). %nelement(X,0,[X|_]). %nelement(X,M,[_|L]):- M>0, N is M-1,nelement(X,N,L). %?-nelement(3,0,[3,2,1,0]). %----------------------- %minimal element in list min(X,[X]). min(X,[H|T]):-min(X,T),X