Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS3 Fall 2005 Lecture 11: Finish higher order functions Midterm Prep.

Similar presentations


Presentation on theme: "CS3 Fall 2005 Lecture 11: Finish higher order functions Midterm Prep."— Presentation transcript:

1 CS3 Fall 2005 Lecture 11: Finish higher order functions Midterm Prep

2 Oct 31More HOF – "tic-tac-toe" program: SS chapter 10! – "Change Making" case study, in the reader Nov 7Miniproject #3: Election-processing – Thursday a catch-up day, Friday is a holiday – MiniProject #3 due Thur/Fri: plan ahead! Nov 14Midterm #2 Lab: Lists (extending words and sentences) Nov 21Start on the project: check-off #1 Nov 28Work on the project: checks #2 Dec 5Checkoff #3, finish the project Dec 17Final Exam (midterm #3)

3 Programming Style and Grading During grading, we are going to start becoming “more strict” on style issues –MiniProject #3 will be the start –For the big project, style is important Why? –Program maintenance: 6 months later, will you know what your code does? –Code “literacy”: sharing code

4 What issues of style matter? Keep procedures small ! Good names for procedures and parameters Adequate comments –Above and within procedures Avoid nesting conditional statements Put tests cases in a comment block Indent to aid program comprehension

5 Midterm 2 Midterm 2: Nov. 14 th (next Monday). –In the lecture slot plus 30 minutes (4-5:30 pm, 120 Latimer) –Practice exam in reader (do this all at once) –Check announcements for more practice items and solutions. Review session –this Wednesday (Nov. 9), 7-9 p.m. –306 Soda Hall (HP Auditorium).

6 What does midterm #2 cover? –Advanced recursion (accumulating, multiple arguments, etc.) –All of higher order functions –Those "big" homeworks (bowling, compress, and occurs-in) –Elections miniproject –Reading and programs: Change making, Difference between dates #3 (HOF), tic-tac-toe –SS chapters 14, 15, 7, 8, 9, 10 –Everything before the first Midterm (although, this won't be the focus of a question)

7 When do you NEED lambda? 1.When you need the context (add-suffix '-is-great '(nate sam mary))  (nate-is-great sam-is-great mary-is-great) 2.When you need to make a function on the fly

8 Procedures that make procedures Generally, name procedures that create procedures "make-XXX" (make-bookends 'o)  #[closure arglist=(inner-wd) d7d0e0] ((make-bookends 'o) 'hi)  ohio ((make-bookends 'to) 'ron)  toronto (define tom-bookend (make-bookends 'tom)) (tom-bookends "")  tomtom

9 Write successive-concatenation (sc '(a b c d e))  (a ab abc abcd abcde) (sc '(the big red barn))  (the thebig thebigred thebigredbarn) (define (sc sent) (accumulate (lambda ?? ) sent))

10 make-decreasing –Takes a sentence of numbers –Returns a sentence of numbers, having removed elements of the input that were not larger than all numbers to the right of them. (make-decreasing '(9 6 7 4 6 2 3 1))  (9 7 6 3 1) (make-decreasing '(3))  (3)

11 Chips and Drinks (snack 1 2)  3 –This includes (chip, drink, drink), (drink, chip, drink), and (drink, drink, chip). (snack 2 2)  6 –(c c d d), (c d c d), (c d d c) (d c c d), (d c d c), (d d c c) "I have some bags of chips and some drinks. How many different ways can I finish all of these snacks if I eat one at a time?

12 Lists (after the midterm) Lists are containers, like sentences where each element can be anything –Including, another list ((beatles 4) (beck 1) ((everly brothers) 2) … ) ((california 55) (florida 23) ((new york) 45) ) (#f #t #t #f #f …)

13 List constructors cons –Takes an element and a list –Returns a list with the element at the front, and the list contents trailing Append –Takes two lists –Returns a list with the element of each lists put together List –Takes any number of elements –Returns the list with those elements

14 List selectors car –Like first cdr –Like butfirst

15 Common list procedures Map = every Filter = keep Reduce = accumulate Null? = empty? Recursion is just the same!


Download ppt "CS3 Fall 2005 Lecture 11: Finish higher order functions Midterm Prep."

Similar presentations


Ads by Google