1 / 13

CS3L: Introduction to Symbolic Programming

CS3L: Introduction to Symbolic Programming. Summer 2008 Colleen Lewis colleenL@berkeley.edu. Lecture 18: HOF. 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

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 18: HOF

  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 starts Today! Due Friday July 25th

  3. Today • lambda • every • keep • Accumulate • Global variables • Tick-tack-toe (ttt)

  4. lambda (lambda(arg1 arg2 …)body…) (define (square x) (* x x)) (define square (lambda (x)(* x x)) THESE ARE THE SAME! (define (square y) (lambda (x) (* x x))) (define square (lambda (y) (lambda (x) (* x x))) These are the same! Called: ((square 1) 4) 16

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

  6. (lambda (‘eat) (word ‘x ‘eat) (lambda (‘get) (word ‘x ‘get) (lambda (‘let) (word ‘x ‘let) every example (define (change-1st-char char sent) (every (lambda (wd)(word char (bf wd))) sent)) > (change-1st-char ‘x‘(eat get let)) (se ‘xat ‘xet ‘xet

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

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

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

  10. accumulate (accumulate (lambda () …) ‘(cat dog hat tag sag) ‘cat  ‘???? ‘dog  ‘??? ‘hat  ‘?? ‘tag ‘sag  ‘?

  11. How to use global variables (define (pi) 3.1415) (define circumference (lambda (diameter) (* diameter (pi)))) (define pi 3.1415) (define circumference (lambda (diameter) (* diameter pi)))

  12. The board X | | ---+---+--- O | O | X ---+---+--- | | "X _ _" "O O X" "_ _ _" "X _ _ O O X _ _ _"

  13. Triples (another representation of a board) X | | ---+---+--- O | O | X ---+---+--- | | "X _ _ O O X _ _ _" ( x23 oox 789 xo7 2o8 3x9 xo9 3o7 )

More Related