1 / 13

CS3L: Introduction to Symbolic Programming

This lecture covers higher-order functions and tick-tack-toe game implementation using lambda functions.

lelandp
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 17: HOF and Tick-Tack-Toe

  2. Today • lambda • every • keep • accumulate • Tick-tack-toe (ttt) • Participation grades • Homework • Miniproject 3 starts next week! Due Friday July 25th • It is already posted… If you want to get started.

  3. lambda (lambda(arg1 arg2 …)body…) • Why do we need lambda? • To do cool things with every, keep, accumulate

  4. 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

  5. (lambda (‘eat) (word ‘eat ‘ing) (lambda (‘get) (word ‘get ‘ing) (lambda (‘let) (word ‘let ‘ing) every example (define (add-suffix suffix sent) (every (lambda (wd)(word wd suffix)) sent)) > (add-suffix ‘ing ‘(eat get let)) (se ‘eating ‘geting ‘leting

  6. 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

  7. (lambda (‘car) (equal? (first ‘car) (first ‘cat))) (lambda (‘bar) (equal? (first ‘bar) (first ‘cat))) (lambda (‘con) (equal? (first ‘con) (first ‘cat))) keep example (define (alliterations wd sent) (keep (lambda (one-wd) (equal? (first one-wd) (first wd))) sent)) > (alliterations ‘cat ‘(car bar con)) (se ‘car ‘() ‘con

  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. remove-dupls > (remove-dupls ‘there) • ‘thre ‘t  ‘thre ‘h  ‘hre ‘e  ‘re ‘r ‘e  ‘re

  10. accumulate example (define (remove-dupls wd) (accumulate (lambda (char wd-so-far) (if (member? char wd-so-far) wd-so-far (word char wd-so-far))) wd))

  11. Tick-Tack-Toe (ttt) Pivot 

  12. Using lambda with define These are VERY DIFFERENT: How would you call each? (define (adder-1 y) (lambda (x) (+ x 1))) (define adder-2 (lambda (x) (+ x 1)))

  13. Participation Grades • I did one of the random participation grading and very few people had done the brainstorm step that I randomly chose. • http://inst.eecs.berkeley.edu/~cs3/su08/reader_files/geninfo.pdf • You will also receive a small number of points for participation and for whether you have worked on particular activities in the on-line materials. Which activities we will check on won't be known to you (or to us, beforehand), but will generally be an activity for which you are asked to answer a question or create a file. The purpose of grading this is to encourage you to keep up-to-date on the lab materials; generally, the grades for these activities will consider whether you attempted it, rather than whether you did it well. You will be docked for participation points if you miss (some) lab sessions, although we may decide to additionally consider how well you contributed to the “community” in your lab session.

More Related