Skip to content

Instantly share code, notes, and snippets.

@diiq
Created November 25, 2012 19:01
Show Gist options
  • Save diiq/4144809 to your computer and use it in GitHub Desktop.
Save diiq/4144809 to your computer and use it in GitHub Desktop.
Evaluator
FAIL = Symbol("Fail")
def eval(code, env):
ret = FAIL
if isinstance(code, Call):
function = eval(code.call, env)
new_env = function.bindings
for arg in function.lambda_list:
if arg.code:
new_env[arg.name] = code.args[arg.name]
else:
new_env[arg.name] = eval(code.args[arg.name], env)
if isinstance(function, Builtin):
ret =function.function(new_env, env)
elif isinstance(function, Lambda):
for c in function.body:
ret = eval(c, new_env)
elif (isinstance(code, Builtin) or
isinstance(code, Number)):
ret = code
elif isinstance(code, Symbol):
ret = env[code.symbol]
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment