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
class05
.
lambda
:
(define (foo x) (* x 12)) (define (bar x) (let ((temp (sqrt x))) (* temp (+ temp 3))))
print-sum
that 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
void
.let
closure, a returned lambda
,
and repeated set!
calls, create a function factory
make-summer
that 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-counter
in the slides.
make-better-summer
that
works like make-summer
, except that the returned procedure
displays the entire sum at each step, and returns void
.> (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