% Prolog translation of the following grammar:
%
%   <even> ::= <empty>
%           |  a a <even>
%
%   <odd> ::= a
%          |  a a <odd>
%
%   <foo> ::= <even> eo <odd>
%          |  <odd> eo <even>


even(T,T).
even([a,a|More],T) :- even(More,T).

even(L) :- even(L, []).

odd([a|T],T).
odd([a,a|More],T) :- odd(More,T).

odd(L) :- odd(L, []).

foo(L,T) :- even(L,[eo|O]), odd(O,T).
foo(L,T) :- odd(L,[oe|E]), even(E,T).

foo(L) :- foo(L,[]).