Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Interpreter Tests
assert seval(23, {}) == 23
assert seval("x", {"x": 23}) == 23
assert seval(("+", 1, 2), env) == 3
assert seval(("+", 1, ("*", 2, 3)), env) == 7
seval(("define", "x", 13), env) == 7
assert seval(("x"), env) == 13
assert seval(("if", ("<", 2, 3), 4, 5), env) == 4
assert seval(("if", (">", 2, 3), 4, 5), env) == 5
assert substitute(('*', ('+', 'x', 'y'), ('x',)), 'x', 2) == ('*', ('+', 2, 'y'), (2,))
factorial = ('define', 'factorial',
('lambda', ('n',), ('if', ('=', 'n', 1), 1, ('*', 'n', ('factorial', ('-', 'n', 1))))))
seval(factorial, env)
seval(('define', 'n', 5), env)
result = seval(('fact', 'n'), env)
assert result == 120
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.