0% found this document useful (0 votes)
200 views1 page

Environment Diagram Rules

Rules on how to draw environment diagrams for python. It's from UC Berkeley's CS61A class with Professor Denero.

Uploaded by

Daniel Au
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
200 views1 page

Environment Diagram Rules

Rules on how to draw environment diagrams for python. It's from UC Berkeley's CS61A class with Professor Denero.

Uploaded by

Daniel Au
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Rules for Environment Diagrams

Remember: The purpose of drawing environment diagrams is to visualize how Scheme evaluates expressions. Preparational work: Start by drawing the Global Environment, set it as your Current Environment. The Golden Rules: 1. Calling a lambda procedure makes frames, pointing to the right bubble of the lambda. 2. Making a lambda procedure makes 2 bubbles, the left holding information and the right pointing to the current frame. The Complete Rules: 1. If the expression is a constant, self-evaluate. There is no need to change anything. 2. If the expression is a symbol, nd the binding in Current Environment. If its not found, go to the environment that the current environment points to and try to and it there. Repeat process until the binding is found. Error if no binding found in the Global Environment. 3. If the expression is a procedure call then: (a) If the procedure being called is a lambda procedure, follow these lambda-proc call rules: i. Evaluate the arguments by recursively applying these same rules ii. Find the right bubble of the procedure were calling, then create a new environment that points to the frame that the right bubble points to and bind formal parameters to their respective arguments. This is the only place you make frames. iii. Set the new environment as your current environment, evaluate the body of the procedure by recursively applying these same rules iv. Go back to the previous current environment after procedure call nishes. (b) If the procedure being called is a primitive procedure, then follow these rules: i. Evaluate the procedure and arguments by recursively applying these same rules ii. Apply the procedure by magic 4. If the expression is a lambda expression, then create two bubbles. The left bubble should point to the parameters and body, and the right bubble points to the current environment. 5. If the expression is a dene expression, convert so it does not use the syntactic shortcut of lambdas, evaluate the second argument, then add a new binding in the current environment to the value. (a) To convert: (define (foo args) body) (define foo (lambda (args) body)) 6. If the expression is a set! expression, then change the rst available binding. 7. If the expression is a let expression, convert it to a lambda procedure call, then follow the lambda-proc call rules. (a) To convert: (let ((a b) (c d)) body) ((lambda (a c) body) b d)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy