Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Interpreter 2: Scope
class Procedure:
def __init__(self, parameters, expressions, env):
self.parameters = parameters
self.expressions = expressions
self.env = env # PROCEDURE MUST REMEMBER THE ENVIRONMENT AT THE TIME THAT IT WAS DEFINED
def __call__(self, *args):
# Args are the argument values
# Make a new scope for the local variables
local_env = {}
# Bind the parameter names to values
for name, value in zip(self.parameters, args):
local_env[name] = value
for expression in self.expressions:
result = seval(expression, {**self.env, **local_env})
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.