This class will be held in the location of our labs, MI 302.
Submit your solutions to the following exercises electronically
in a file called
ex.scm contained in a folder called
(define (foo x) (* x 12)) (define (bar x) (let ((temp (sqrt x))) (* temp (+ temp 3))))
print-sumthat takes a list of numbers and prints the numbers with plus signs between.
> (print-sum '(1 2 3)) 1 + 2 + 3 > (print-sum '(5)) 5The function should return
letclosure, a returned
lambda, and repeated
set!calls, create a function factory
make-summerthat returns a procedure which takes a single number, adds it to a running sum, and returns that running sum. For example:
> (define summer (make-summer)) > (summer 4) 4 > (summer 10) 14 > (summer 10) 24Hint: start with the code for
make-counterin the slides.
make-better-summerthat works like
make-summer, except that the returned procedure displays the entire sum at each step, and returns
> (define bs (make-better-summer)) > (bs 10) 10 = 10 > (bs 4) 4 + 10 = 14 > (bs 8) 8 + 4 + 10 = 22 > (bs 16) 16 + 8 + 4 + 10 = 38