# Prolog:append

Page 1 of 1

## 0 Replies - 787 Views - Last Post: 15 April 2009 - 07:24 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=99480&amp;s=f3843a66b12c11fd49dc0d2fbbc1df97&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 chetah

Reputation: 2
• Posts: 112
• Joined: 17-November 07

# Prolog:append

Posted 15 April 2009 - 07:24 AM

I am looking a problem here and need some help

recursive definition of append

append([]A,A).
append([H|T1], A, [H|T2]):-(T1, A, T2)

(a.) ?-append(L,[x,z],[y,x,z]

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

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)

need some guidance struggling here
[1]|[,2,3]
[2][3]
[3]

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }