Environments vs Frames in The Environment Model of Evaluation (SICP)

Viewed 20

I found this section (3.2) of SICP pretty vague on the exact difference between an environment and a frame. Sometimes it seemed to use them interchangeably, and sometimes it labelled them as distinct things, but it was very hard to tell what the difference was.

The big point of the section of course is that if a variable isn't bound in the environment/frame that a procedure is executed in then it's value is looked up in the enclosing environment/frame, or else the one enclosing that etc etc. That's all very simple and clear.

However, what's unclear is the environment vs frame distinction.

We're told that:

  • "an environment is a sequence of frames"
  • a frame is basically a table of key-value bindings
  • a frame has a pointer to its enclosing environment
  • a procedure is evaluated in an environment

The clearest it gets is this figure:

A simple environment structure

with frames labelled I, II and III and environments labelled A, B, C and D. But of course all of the environments point to frames.

The best sense I can make of these statements is that, referring to this figure and assuming there's a global environment, G, above frame I:

  • a frame is a concrete table of key-value pairs which includes a special binding with some special name where the value is the parent frame of this one. i.e. II might be a map like { z: 6, x: 7, __parent__: <I> }.
  • a procedure is a pair where:
    • the first element points to something that holds a list of parameters as well as the body of the procedure
    • the second element is a pointer to a frame, which maybe is the environment
  • an environment is either:
    • the pointer I just mentioned and/or
    • it is (a pointer to?) the sequence of frames, e.g. '(II, I, G), that will be traversed to retrieve a value for a key
    • it is the abstract concept of the set of key-value bindings you'd get by merging II, I and G with the first frame to define a binding taking precedence, and so we say that a procedure is evaluated in an environment (rather than, e.g. against a frame) to encapsulate the abstract idea of a collection of all the bindings available to the procedure, even if in practice they're each potentially coming from any of a sequence of frames according to the hierarchical lookup process.

Can anyone who understands where SICP is pulling this terminology from tell me if I'm on the right track here or better clarify what is an environment and what is a frame and when it would be wrong to use one term over the other?

0 Answers
Related