Environment Diagrams

Long live the Environment Model. This is how things Really Work, so it's important to know. The best reference for how to do things in the environment model is in your Volume II reader on page 320 (or page 54 of the PDF lecture notes), and the most important lines (marked with asterisks) are repeated here:

There are two more important rules (they're in the reader but not emphasized on that page):

A lot of people are often confused between the difference between a frame and an environment. Independent of the diagrams, a frame is a map of variable names and the values they are bound to. An environment is a list of frames, which is traversed in order when you look up the value of a variable.

In the diagrams, one rectangle is a frame. The chain of rectangles and arrows back to the global environment is an environment. (In Scheme, every environment is an extension of the global environment.)

We often use the term "global environment" when we really mean "global frame". Since the global environment is the list of one frame, though (the global frame), we are at least not being ambiguous about, say, where a variable has been defined.

EnvDraw and Practice Problems

What's EnvDraw, you ask? It draws environment diagrams (and box-and-pointer diagrams) for you! To use it, run the program envdraw at the shell (instead of emacs& or stk). This starts a special version of STk running an interpreter that draws any changes to the environment in a window. You can also use M-x run-envdraw in Emacs to run it in the current split.

Note that you can't use define-class with EnvDraw, so you can't make it automatically show you the below-the-line representation of a class.

If you're connecting from home, make sure you turn on X forwarding (running Xming or Xceed on Windows, or using ssh -X on Mac or Linux), just like you did for the picture project.

For these practice problems, draw the environment, then log into an inst machine and use EnvDraw to check your answers. Don't skip steps, just go very carefully!

Back to Jordy's home page | Course home page