Chapter 4, Metalinguistic Abstraction

Exercise 4.17


Why extra frame?

Because let is transformed into a lambda creation and invocation. And lambda invocation creates a frame.

Why this difference won’t cause any behaviour change?

Because the new lambda does not do anything extra from the original procedure.

Design a new way to avoid extra frame creation.

Instead of creating let, we can just put the definitions like (define x '*unassigned*) in the beginning of the body and replace all the existing definitions by set!. For eg:

If we have a procedure:

1
2
3
4
5
6
(define (test x)
  (set! x (+ x 1))
  (define a 0)
  (set! a (+ a 1))
  (define b 1)
  (+ x a b))

It gets transformed to:

1
2
3
4
5
6
7
8
(define (test x)
  (define a '*unassigned*)
  (define b '*unassigned*)
  (set! x (+ x 1))
  (set! a 0)
  (set! a (+ a 1))
  (set! b 1)
  (+ x a b))