# e 24 task write a predicate even1 that generates the

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: y cut in half Note: this is not a recursive solu=on midlist(L,Middle) :append(Left,[Middle|Right],L), length(Left,N), length(Right,N). Today’s Topics •  Homework 2 review •  reverse/3 from last =me •  Prac=ce makes perfect… –  more prac=ce wri=ng programs Last Time a recursive predicate for reversing lists rev(,). rev([X|L],R) :rev(L,LR), append(LR,[X],R). •  reverse/2 is a built ­in predicate in SWI ­Prolog Example: [1,2,3] [2,3] [3] [3,2,1] [3,2] 1 [3] 2 3 reverse without using append/3 •  deﬁne rev/2 as: rev(L,R) :rev(L,,R). •  deﬁne rev/3: rev(,L,L). rev([X|L1],L2,L3) :rev(L1,[X|L2],L3). Key idea: use two stacks 17 Today’s Topics •  Homework 2 review •  reverse/3 from last =me •  Prac=ce makes perfect… –  more prac=ce wri=ng programs Natural Numbers (NN) •  Infinite set: –  N = {1,2,3,4,5,..} •  Base case nn(1).! –  “1 is a natural number”...
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