Last active
November 3, 2019 23:05
-
-
Save chelseatroy/cfca7b237ebc4ad5d73eaa994b9d315e to your computer and use it in GitHub Desktop.
Interpreter 1: No Scope (excerpt)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Procedure: | |
def __init__(self, parameters, expressions, env): | |
self.parameters = parameters | |
self.expressions = expressions | |
self.env = env | |
def __call__(self, *args): | |
for expression in self.expressions: # Substitute the arguments for parameter names | |
for names, values in zip(self.parameters, args): | |
expression = substitute(expression, names, values) | |
result = seval(expression, # Evaluate the resulting expression | |
dict(self.env)) # makes a copy of env | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment