1 / 15

CS3L: Introduction to Symbolic Programming

CS3L: Introduction to Symbolic Programming. Summer 2008 Colleen Lewis colleenL@berkeley.edu. Lecture 19: HOF Problems. Announcements. Midterm two Tuesday July 29 th This one will probably be harder than the first Colleen will be out of town Thurs-Monday Homework

wes
Download Presentation

CS3L: Introduction to Symbolic Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS3L: Introduction to Symbolic Programming Summer 2008 Colleen Lewis colleenL@berkeley.edu Lecture 19: HOF Problems

  2. Announcements • Midterm two Tuesday July 29th • This one will probably be harder than the first • Colleen will be out of town Thurs-Monday • Homework • Miniproject 3 started yesterday! • Due Friday July 25th at 11:59 pm • Today is Gilbert’s 7,000th day! And we’re having a surprise party for him!

  3. Today • Problem:Successive-concatenations • Which HOFs should I use? • Work on the mini-project • Let me know if you don’t have a partner and want one

  4. Successive Concatenations (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))

  5. Successive Concatenations (accumulate (lambda () …) ‘(the big red barn) ‘the  ‘(the thebig thebigred thebigredbarn) ‘big  ‘(big bigred bigredbarn) ‘red ‘barn  ‘(red redbarn)

  6. Successive Concatenations (accumulate (lambda () …) ‘(the big red barn) (lambda (new-wd so-far) (every (lambda (wd) (word new-wd wd)) (se “” so-far))) (proc ‘big ‘(red redbarn))  ‘(big bigred bigredbarn)

  7. Successive Concatenations (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 (new-wd so-far) (every (lambda (wd) (word new-wd wd)) (se “” so-far)) sent))

  8. accumulate (accumulateprocedure sent) • procedure • a procedure that takes in two arguments • a procedure that combines things together • sent • a sentence with 1 or more words • a word with 1 or more letters

  9. every (everyprocedure sent) • procedure • a procedure that takes in one argument • a procedure that returns a word or a sentence • sent • a sentence with 0 or more words • a word with 0 or more letters

  10. keep (keepprocedure sent) • procedure • a procedure that takes in one argument • a procedure that returns #t or #f • sent • a sentence with 0 or more words • a word with 0 or more letters

  11. Which HOFs would you use? • Capitalize-proper-names (c-p-n '(mr. smith goes to washington)) (mr. Smith goes to Washington) • Every • Keep • Accumulate

  12. Which HOFs would you use? • Longest Word (longest-word '(have a great week))  great • Every • Keep • Accumulate

  13. Which HOFs would you use? • Count-if odd? (count-if odd? '(1 2 3 4 5))  3 (count-if odd? '(1 2 3 4 2))  2 • Every • Keep • Accumulate

  14. Which HOFs would you use? • Count-vowels-in-each (c-v-i-e '(good luck on tuesday))  (2 1 1 3) • Every • Keep • Accumulate

  15. Which HOFs would you use? • Squares-greater-than-100 (s-g-t-100 '(2 9 13 16 9 45))  (169 256 2025) • Every • Keep • Accumulate

More Related