Introduction

Environment Diagrams may seem tricky at first but they’re really useful in analyzing how functions are evaluated. If you follow these simple steps, you’ll be able to draw out any environment diagram. As with all things CS-related, practice, practice, practice!

The Steps

Follow these steps below for a successful environment diagram:

  1. Draw the global frame. No questions asked, just draw it.
  2. When evaluating assignment statements (lines with a single equals sign), always, always, always remember to evaluate the right side first!
  3. When you call a function, MAKE A NEW FRAME!
  4. When assigning a primitive expression to a variable, write that value directly in the box.
  5. When assigning anything else besides a primitive expression to a variable, draw an arrow to that value.
  6. Bind imported values in the current frame (represent the inside of the function with an ellipsis (…)).
  7. When calling a function (see #3), name the frame with the intrinsic name of the function – that is, write the name of the function that your variable points to!
  8. The parent frame of a function is the frame in which it was defined in.

List of things not to do:

  1. Never, ever, ever draw an arrow from one variable to another. Remember, arrows always point to values, not other variables.
  2. Don’t draw frames for built-in functions.

Lastly, like I said before, make sure you practice!

I don't claim to be perfect so if you find an error on this page, please send me an email preferably with a link to this page so that I know what I need to fix!

comments powered by Disqus