chetah Posted April 15, 2009 Share Posted April 15, 2009 Need some help with this question recursive definition of append append([]A,A). append([H|T1], A, [H|T2]):-(T1, A, T2) (a.) ?-append(L,[x,z],[y,x,z] my answer L3 = [L]|[Lo] ?- append ([], [x,y], L0. L0 = []|L1 (b.) write rule for append1(l1, l2, l3,l4) to be true if and only if l4 is the same as l1,l2, and l3 append in that order my answer append1([], A, A, A). append1([H|T1], A, A, [H|T4]):-append1(T1, A, A, T4) (c.) using append write rule to define shorten(l1, l2) to be true if and only if l2 can be obtained by removing the first and last elements of l1. shorten(L1, L2) :- shorten([H]|[_N], L2) (d.) use shorten write rule that defines even(l) to be true if and only if l is a list of even number shorten(l1,l2):-even(l,X) //where x is 2 (e.) state steps prolog would take to solve shorten([1,2,3],l) [1]|[,2,3] [2][3] [3] Link to comment Share on other sites More sharing options...
Question
chetah
Need some help with this question
recursive definition of append
append([]A,A).
append([H|T1], A, [H|T2]):-(T1, A, T2)
(a.) ?-append(L,[x,z],[y,x,z]
my answer
L3 = [L]|[Lo]
?- append ([], [x,y], L0.
L0 = []|L1
(b.) write rule for append1(l1, l2, l3,l4) to be true if and only if l4 is the same as l1,l2, and l3 append in that order
my answer
append1([], A, A, A).
append1([H|T1], A, A, [H|T4]):-append1(T1, A, A, T4)
(c.) using append write rule to define shorten(l1, l2) to be true if and only if l2 can be obtained by removing the first and last elements of l1.
shorten(L1, L2) :- shorten([H]|[_N], L2)
(d.) use shorten write rule that defines even(l) to be true if and only if l is a list of even number
shorten(l1,l2):-even(l,X) //where x is 2
(e.) state steps prolog would take to solve shorten([1,2,3],l)
[1]|[,2,3]
[2][3]
[3]
Link to comment
Share on other sites
0 answers to this question
Recommended Posts