Exercise 4.13. Scheme allows us to create new bindings for variables by means of define, but provides no way to get rid of bindings. Implement for the evaluator a special form make-unbound! that removes the binding of a given symbol from the environment in which the make-unbound! expression is evaluated. This problem is not completely specified. For example, should we remove only the binding in the first frame of the environment? Complete the specification and justify any choices you make. ———————————————————————————————————————————————————————————————————————— If a variable binding exists in any visible environment, set! can be used to alter its value. For consistency we will all make-unbound! to work the same way. (define (eval exp env) (cond ... ((make-unbound!? exp) (unbind-variable! (make-unbound!-var exp) env)) ...)) The apply-to-vals procedure from the previous excercise can be extended to allow changing both the var and val lists: (define (apply-to-vars-vals var proc frame) (define (scan vars vals) (cond ((null? vars) #f) ((eq? (car vars) var) (proc vars vals)) (else (scan (cdr vars) (cdr vals))))) (scan (frame-variables frame) (frame-values frame))) And unbind-variable! can be implemented in these terms: (define (unbind-variable! var env) (if (eq? env the-empty-environment) (error "Unbound variable in unbind-variable!" var) (let* ((frame (first-frame env)) (result (apply-to-vars-vals var (lambda (vars vals) (set-car! vars (cdr vars)) (set-car! vals (cdr vals)) #t) frame))) (if result 'ok (unbind-variable! var (enclosing-environment env)))))) as discussed at meeting: (set-car! vars (cdr vars)) is completely wrong to remove an element from a list. Aamar presented a correct solution using: (define (delete-head! list) (set-car! list (cadr list)) (set-cdr! list (cddr list)))