Problem 2: Make Adder (100 pts)
Write the procedure make-adder
which takes in an initial number, n
, and then returns a procedure. This returned procedure takes in a number x
and returns the result of x + n
.
Hint: To return a procedure, you can either return a lambda
expression or define
another nested procedure. Remember that Scheme will automatically return the last clause in your procedure.
(define (make-adder n)
'YOUR-CODE-HERE
)
;;; Tests
; scm> (define adder (make-adder 5))
; adder
; scm> (adder 8)
; 13