6.001 Recitation #7 A.R. Meyer NOTES FOR WED, 9/24 In class problems: PROBLEM 1 Consider (define (times3 n) (* 3 n)) so (times3 7) => 21, (times3 -2) => -6, and so on. 1A: What is the TYPE of times3? 1B: Now a procedure MAKE-TIMESN such that times3 could be defined as (define times3 (make-timesn 3)) and so that if we defined, for example, (define times-half (make-timesn (/ 1 2))) then (times-half 6) => 3, (times-half 7) => 3.5, etc. 1C: What is the TYPE of MAKE-TIMESN? PROBLEM 2 Suppose we have a calculator with function button numbered say F0, F1, F2, where F0 is the ADD operation, F1 the TIMES operation, and F2 the SUBTRACT operation. We want to simulate the calculator with a procedure CALC such that, for example, ((calc 0) 3 4) ==> 7 ;ADD the two operands ((calc 1) 3 4) ==> 12 ;MULTIPLY the two operands ((calc 2) 3 4) ==> -1 ;SUBTRACT the two operands 2A: Define the procedure CALC. 2B: WHat is the type of CALC? SOLUTIONS 1A: SN-->SN where SN is `Scheme-Number' 1B: We want ((make-timesn m) k) => M * K where M is the value of m and K is the value of k: (define (make-timesn m) (lambda (k) (* m k))) 1C: SN-->(SN-->SN) 2A: (define (calc n) (cond ((= 0 n) +) ((= 1 n) *) ((= 2 n) -) (else (error "calculator only has buttons 0-2. you pressed: " n)))) 2B: SN--> ((SN x SN) --> SN)