G midlistabcdex xc midlistabcdx no

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: pick out the middle element of a list –  (if there is no middle element, it should fail to return an answer) –  e.g. ?- midlist([a,b,c,d,e],X). X=c –  ?- midlist([a,b,c,d],X). No •  Possible lists –  –  –  –  –  –  [a] [a,b] [a,b,c] [a,b,c,d] [a,b,c,d,e] List Key observa.on: recursive case such that concatena=ng List’ with Last = Tail List = [Head|Tail] i.e. append(List’,[Last],Tail) is true Head List’ Last a List’ e Homework 2 Review •  Exercise 2 (6pts): –  Write a recursive defini=on midlist/2 to pick out the middle element of a list –  (if there is no middle element, it should fail to return an answer) –  e.g. ?- midlist([a,b,c,d,e],X). X=c –  ?- midlist([a,b,c,d],X). No •  Possible lists –  –  –  –  –  –  [a] [a,b] [a,b,c] [a,b,c,d] [a,b,c,d,e] List = [Head|Tail] Head List’ Last append(List’,[Last],Tail) is t...
View Full Document

This note was uploaded on 04/29/2012 for the course LING 388 taught by Professor Staff during the Fall '08 term at University of Arizona- Tucson.

Ask a homework question - tutors are online