isPrime(X) :- X>1, 1<J<X, not X mod J /= 0.
sort(X, Y) :- permutation(X, Y), isOrdered(Y).
{x in X| odd(x)}
-- subset of X which are odd
exists x in X|Pred(x)
-- true if there exists an element in X which satisfies Pred
[x:x in [2..100]|not exists y in [2..x-1]|x mod y=0]
-- the tuple of all primes less than 100
E : E '+' E ; E : E '*' E ; E : Identifier ;
alpha [a-z]
numeric [0-9]
%%
{alpha}({alpha}|{numeric})* { return Identifier;}
ws = ' ' subject = 'I' | 'We' verb = 'see' | 'hit' | 'grab' object = 'him' | 'her' | 'you' sentence = subject ws verb ws object ws '.' input = We see you. input sentence :S(found)F(notfound)
tvShow(theSimpsons, on(fox, date(sunday), time(8,00)))
mother(marge,bart). father(homer,bart). mother(marge,lisa). father(homer,lisa). mother(marge,maggie). father(homer,maggie).
siblings(X,Y):-mother(M,X),mother(M,Y),father(D,X),father(D,Y).
?- mother(marge, Y). Y = bart
; Y = lisa ; Y = maggie ; no
sumToN(L,L,L). sumToN(L,U,R) :- L<=U, NewU is U - 1, sumToN(L,NewU,NewR), R is U+NewR.
print(U,U) :- write(U), nl. print(L,U) :- L < U, write(L), nl, M is L+1, print(M, U).
simpson([maggie, bart, lisa, homer, marge]). member(X,[X|T]). member(X, [H|T]) :- X /== H, member(X, T).
append([],L,L). append([H|T],L,[H|NewT]) :- append(T,L,NewT).
% cprolog (usually in /usr/public/bin) ?- consult(mydefs). mydefs consulted 816 bytes 0.06 sec. ?- father(Y, bart). Y = homer ?- ^D [ Prolog execution halted ]