1 / 9

CS3L: Introduction to Symbolic Programming

CS3L: Introduction to Symbolic Programming. Summer 2008 Colleen Lewis colleenL@berkeley.edu. Lecture 12: Homework stuff and Accumulating Recursion. Today. I’m sick. I’m going home after lecture, but I’ll be online Homework Thurs: Bowling (Hwk11) due Monday

jason
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 12: Homework stuff and Accumulating Recursion

  2. Today • I’m sick. • I’m going home after lecture, but I’ll be online • Homework • Thurs: Bowling (Hwk11) due Monday • Fri: Compress/occurs-in? (Hwk12) due Tuesday • Mon: Mini-project 2 due Wednesday • Testing the Bowling Program • Accumulating Recursion • Compressed • Occurs-in?

  3. Testing Bowling • Don’t start programming before you can calculate a bowling score by hand • Test with simple cases • ‘(10 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) • The last frame is complicated!

  4. Accumulating Recursion (define (gather-evens sent) (cond ((empty? sent) ‘()) ((even? (first sent)) (se (first sent) (gather-evens (bf sent)))) (else (gather-evens (bf sent))))

  5. (se 2 (gather-evens‘( 3 4 5 6 )) (gather-evens‘( 4 5 6 )) (se 4 (gather-evens ‘( 5 6 )) (gather-evens ‘( 6 )) (se 6 (gather-evens ‘( )) > (gather-evens '(2 3 4 5 6)) (gather-evens ‘( 2 3 4 5 6 )) ‘() • (se 2 (se 4 (se 6 ‘()))) • (2 4 6)

  6. Accumulating Recursion (define (gather-evens evens-so-far sent) (cond ((empty? sent) evens-so-far) ((even? (first sent)) (gather-evens (se evens-so-far (first sent)) (bf sent))) (else (gather-evens evens-so-far (bf sent)))) (define (gather-evens sent) (cond ((empty? sent) ‘()) ((even? (first sent)) (se (first sent) (gather-evens (bf sent)))) (else (gather-evens (bf sent))))

  7. Final Version of gather-evens w/ Accumulating Recursion (define (gather-evens evens-so-far sent) (cond ((empty? sent) evens-so-far) ((even? (first sent)) (gather-evens (se evens-so-far (first sent)) (bf sent))) (else (gather-evens evens-so-far (bf sent))))

  8. Homework - Compressed • (0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 1 1 1) • ( 4 0 1 4 0 9 1) • (0 1 0 1) • (0 1 0 1)

  9. Homework - Occurs-in? • (occurs-in? 'abc 'abcde) #t • (occurs-in? 'abc 'xyabc) #t • (occurs-in? 'ab 'axbc) #f • (occurs-in? 'abc 'xy) #f • This is not an exhaustive list!!!

More Related