def test_apply(self): env = Environment(primitive_procedure_names, primitive_procedure_objects) # test compound procedure parameters = ["x"] body = [1, 2] procedure = eval.make_procedure(parameters, body, env) self.assertEqual(eval.apply(procedure, [1]), 2) # test primitive procedure add = env.get_binding('+') self.assertEqual(eval.apply(add, [1, 2]), 3) # test exception procedure = ["!!!!!", ["x"], [1, 2], env] with self.assertRaises(ApplyError): eval.apply(procedure, [1])
def schemeCallcc(self, cont, env, args): lambdaBody = args[0] def c2(val): return pogo.bounce(cont, val) cont_procedure = expressions.makeContinuationProcedure(c2) return evaluator.apply(lambdaBody, pair.list(cont_procedure), env, cont)
def schemeApply(self, cont, env, args): return evaluator.apply(args[0], args[1], env, cont)