def test_calling_builtin_forces_argument_evaluation(self): """Bultins (like the regular lambdas) are call-by-value and the arguments thould therefore be evaluated first""" env = Environment({ 'x': integer(2), '+': Builtin(lambda a, b: integer(value_of(a) + value_of(b))) }) ast = ['+', ['cond', [boolean(True), integer(2)], [boolean(True), 'whatever']], 'x'] assert_equals(integer(4), evaluate(ast, env))
def test_false(self): assert_false(value_of(tag('bool', False)))
def test_true(self): assert_true(value_of(tag('bool', True)))
def test_getting_value_of_type(self): t = tag('footype', 42) assert_equals(42, value_of(t))
def test_calling_a_builtin_function(self): """Tests that calling a builtin function gives the expected result""" env = Environment({'+': Builtin(lambda a, b: integer(value_of(a) + value_of(b)))}) assert_equals(integer(4), evaluate(["+", integer(2), integer(2)], env))