Rules of Environment Diagrams
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!
Follow these steps below for a successful environment diagram:
- Draw the global frame. No questions asked, just draw it.
- When evaluating assignment statements (lines with a single equals sign), always, always, always remember to evaluate the right side first!
- When you call a function, MAKE A NEW FRAME!
- When assigning a primitive expression to a variable, write that value directly in the box.
- When assigning anything else besides a primitive expression to a variable, draw an arrow to that value.
- Bind imported values in the current frame (represent the inside of the function with an ellipsis (…)).
- 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!
- The parent frame of a function is the frame in which it was defined in.
List of things not to do:
- Never, ever, ever draw an arrow from one variable to another. Remember, arrows always point to values, not other variables.
- 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!