Alternative Version Analysis
procedure, the local variable
is created as a parameter of
. We could also create the local state variable explicitly, using
, as follows:
(define (make-withdraw initial-amount) (let ((balance initial-amount)) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds"))))
Recall from section
is simply syntactic sugar for a procedure call:
(let ((<var> <exp>)) <body>)
is interpreted as an alternate syntax for
((lambda (<var>) <body>) <exp>)
Use the environment model to analyze this alternate version of
, drawing figures like the ones above to illustrate the interactions
(define W1 (make-withdraw 100)) (W1 50) (define W2 (make-withdraw 100))
Show that the two versions of
create objects with the same behavior. How do the environment structures differ for the two versions?
Nobody's finished this exercise yet. You'll be the first!
There are no comments yet.
You must log in to post a comment.Login