% mem( X, L ) is true if X is a member of L % it's true that member is built-in to some versions of prolog mem( X, [X|_] ). mem( X, [_|R] ) :- mem( X, R ). % len( L, N ) is true iff L is a list of length N: len( [], 0 ). len( [_|R], N ) :- len( R, M ), N is M+1. % app( A, B, L ) is true iff L is the concatentation of A and B app( [], L , L ). app( [F|R1], L, [F|R2] ) :- app( R1, L , R2 ). % lastof( X, L ) is true iff X is the last element of L lastof( X, [X] ). lastof( X, [_|R] ) :- lastof( X, R ). % sum( L, N ) is true iff N is the sum of L's (all-numeric) elements sum( [], 0 ). sum( [F|R], N ) :- sum( R, M ), N is M+F. % nextto(X,Y,L) is true if X is next to Y in L nextto( X, Y, [X,Y|_] ). nextto( X, Y, [Y,X|_] ). nextto( X, Y, [_|R] ) :- nextto( X, Y, R ). % start( L1, L2 ) is true if L1 is the start of L2 (both are lists) start( [], _ ). start( [F|R], [F|R2] ) :- start( R , R2 ). % sublist( S, L ) is true if S is a sublist of L (both are lists) sublist( [], _ ). sublist( [F|R1], [F|R] ) :- start( R1, R ). sublist( S, [_|R] ) :- sublist( S, R ).