CA 208 Logic - DCU School of Computing

Download Report

Transcript CA 208 Logic - DCU School of Computing

CA 208 Logic Ex9
Define the following list processing predicates in
Prolog:










member(X,L)
last_member(X,L)
last_two_members(X,Y,L)
odd_list(L)
even_list(L)
insert(X,L1,L2)
delete(X,L1,L2)
conc(L1,L2,L)
reverse(L1,L2)
% if X is a member of list L
% if X is the last member of list L
% if X and Y are the last two members of list L
% if L has odd number of elements
% if L has even number of elements
% if list L2 is list L1 with X inserted
% if list L2 is L1 with X deleted
% if list L is the concatenation of L1 with L2
% if list L2 is the reverse of L1
1
CA 208 Logic Ex9
Define a “waffle”-machine in Prolog as a FiniteState Automaton that accepts/generates the
infinite language (coded as Prolog lists):





[]
[b,l,a,h]
[b,l,a,h,b,l,a,h]
[b,l,a,h,b,l,a,h,b,l,a,h, ....]
2