Lesson Plan - 6.001 SP04 - recitation 2 More Scheme Administrivia * project due today 6pm * tutorials next week - everyone scheduled? * project 1 out Lecture review if (if test cons alt) test not false why special form? lambda (lambda params body) favorite makes a compound procedure eval/apply cond - variant of if table Solutions: 1. (if #t (+ 1 1) 17) ;Value: 2 (if #f #f 42) ;Value: 42 (if (> x 0) x (- x)) ;Value: 3 (if 0 1 2) ;Value: 1 (if x 7 (7)) ;Value: 7 2. (lambda (x) x) ;Value: #[compound-procedure 2] ((lambda (x) x) 17) ;Value: 17 ((lambda (x y) x) 42 17) ;Value: 42 ((lambda (x y) y) (/ 1 0) 3) ;Hardware trap INT_DIVIDE_BY_ZERO ((lambda (x y) (x y 3)) (lambda (a b) (+ a b)) 14) ;Value: 17 3. (define biggie-size (lambda (combo) (+ 4 combo))) (define unbiggie-size (lambda (combo) (- combo 4))) (define biggie-size? (lambda (combo) (> combo 4))) (define combo-price (lambda (combo) (if (biggie-size? combo) (+ .5 (* 1.17 (unbiggie-size combo))) (* 1.17 combo)))) (define empty-order (lambda () 0)) (define add-to-order (lambda (order combo) (+ (* 10 order) combo))) (define order-size (lambda (order) (if (= order 0) 0 (+ 1 (order-size (quotient order 10)))))) (define order-price (lambda (order) (if (= order 0) 0 (+ (combo-price (remainder order 10)) (order-price (quotient order 10))))))