%% -*- prolog -*-

% man(aristotle).			% fact
% man(aristotle) :-.		% equivalent to degenerate rule

% mortal(X) :- man(X).

% father(X,Y) :- man(X), parent(X,Y).

% b(A1,A2,A3,B1,B2,B3,C1,C2,C3)

% b(A,B,C)

has1(1,B,C).
has1(A,1,C).
has1(A,B,1).

has2(2,_,_).
has2(_,2,_).
has2(_,_,2).

has3(3,_,_).
has3(_,3,_).
has3(_,_,3).

hasall(A,B,C) :- has1(A,B,C), has2(A,B,C), has3(A,B,C).

hasx(X,X,_,_).
hasx(X,_,X,_).
hasx(X,_,_,X).

hasall2(A,B,C) :- hasx(1,A,B,C), hasx(2,A,B,C), hasx(3,A,B,C).

%% rep for lists:
%%  nil = empty list
%%  cons(E,L) for list starting w/ E and continuing w/ list L
mem(X,cons(X,L)).
mem(X,cons(_,L)) :- mem(X,L).

%%% rewrite "has" using lists & mem

equal(X,X).

has(L) :- equal(L,cons(_,cons(_,cons(_,nil)))),
	mem(1,L), mem(2,L), mem(3,L).

%%% Syntactic Sugar for LISTS:

%% empty list: []
%% list starting w/ E continuing w/ L, uses .(E,L)
%% sugared syntax: [E|L] for .(E,L)
%%                 [x,y,z,a,b,c] for .(x,.(y,.(z,.(a,.(b,.(c,[]))))))
%%                 [x,y,z|L] for .(x,.(y,.(z,L)))
%%  the list [x,y,z|L] has length 3 + length of L.
