% Class Examples for cs415: Fall 2005
% % is the start of a comment.

likes(fred,hamburgers).
likes(sue,fondue).     
likes(sue,figureskating).     
likes(fred,fondue).     
likes(fred,figureskating).     
likes(fred,snowboarding).
likes(fred,hockey). 
likes(mary,beer).
likes(mary,hockey). 
likes(mary,curling).
likes(bob,pancakes).
likes(bob,fondue).     
likes(bob,curling).

american(X) :-
    likes(X,hamburgers),
    likes(X,snowboarding).

% In order to be a european you must like fondue AND figureskating.
% comma means AND
%european(X) :-
%   likes(X,fondue),
%   likes(X,figureskating).

% In order to be a european you must like fondue OR figureskating.
% semicolon means OR
european(X) :-
    likes(X,fondue); likes(X,figureskating).   

% Another way to do an OR is to have two separate clauses.
%european(X) :-
%   likes(X,fondue).
%european(X) :-
%   likes(X,figureskating).

canadian(X) :-
    likes(X,beer),
    likes(X,hockey).

friends(X,Y, Something) :-
    likes(X, Something),
    likes(Y, Something),
    not(X = Y).

print_fondue_lovers(X) :- write(X), nl, likes(X,fondue).

edge(a,b). edge(b,c). edge(c,d).
edge(d,e). edge(b,e). edge(d,f).
path(X,X).
path(X,Y) :- edge(Z,Y), path(X,Z).

append([], L, L).
append([H|T], L, [H|L2]) :- append(T, L, L2).

% Variables that start with an _ are anonymous variables.
% (If you take off the _'s below, the interpreter will give
% a warning when you load the file.)
% In the case of _H and _T, we need to use a variable, but
% that variable will not be referred to again, so we can
% make it anonymous.
member(X, [X|_T]).
member(X, [_H|T]) :- member(X, T).

print_partitions(L) :- append(A, B, L),
    write(A), write(' '), write(B), nl,
    fail.

rainy(seattle).
rainy(rochester).
cold(rochester).
snowy(X) :- rainy(X), cold(X).

natural(1).
natural(N) :- natural(M), is(N, M+1).

param_loop(L, H, F) :- natural(I), >=(I, L), =<(I, H),
    G =.. [F, I], call(G),
    I = H, !,  fail.

my_loop(N) :- natural(I), I=< N,
    write(I), nl, I = N, !, fail.

