def test_letrec_odd_even(self): from util import n, odd, even eq_( eval( letrec([(odd, lamda([n], if_(eq(n, 0), 0, even(sub(n, 1))))), (even, lamda([n], if_(eq(n, 0), 1, odd(sub(n, 1)))))], odd(3))), 1)
def test_letrec_fac(self): from util import m, n, fac eq_( eval( letrec([ (fac, lamda([n], if_(eq(n, 1), 1, mul(n, fac(sub(n, 1)))))) ], fac(3))), 6)
def test_letrec(self): f, k, function = il.Var('f'), il.Var('k'), il.Var('function') result = cps(letrec([(f, lamda((), f()))], f())) expect = il.Clamda(v, il.Assign(f, v), v)(il.Lamda( (k, ), il.Clamda(function, function(k))(f))) eq_(result, expect)
def test_chars(self): x, cs, chars = LogicVar('x'), Var('cs'), MacroVar('chars') x1 = Var('x') eq_( eval( let([(chars, lamda( (x1, cs), begin(char(x1), contain(cs, x1))))], parse_text(chars(x, 'a'), 'a'), getvalue(x))), 'a')
def test_letrec(self): f, k, function = il.Var('f'), il.Var('k'), il.Var('function') result = cps(letrec([(f, lamda((), f()))], f())) expect = il.Clamda(v, il.Assign(f, v), v)( il.Lamda((k,), il.Clamda(function, function(k))(f))) eq_(result, expect)
def testblock(self): f = Var('f') foo = Var('foo') eq_( eval( block( foo, let([(f, lamda((), exit_block(foo, 1)))], mul(2, block(foo, f()))))), 1)
def testletdouble(self): x, f = Const('x'), Const('f') eq_(eval(let([(f, lamda([x], add(x, x)))], f(1))), 2)
def test_letrec3(self): x, f = Var('x'), Var('f') eq_( eval( letrec([(f, lamda((x, ), if_(eq(x, 1), 1, f(sub(x, 1)))))], f(2))), 1)
def test_letrec_assign2(self): x, f = Const('x'), Const('f') assert_raises(MultiAssignToConstError, eval, letrec([(f, lamda((x, ), f(1), assign(f, 1)))], f(2)))
def test_lamda2(self): x, x1, y, y1, k = Var('x'), Var('x1'), Var('y'), Var('y1'), Var('k') eq_(alpha(lamda((x, y), lamda((x, ), x, y), x)), lamda((x, y), lamda((x1, ), x1, y), x))
def test_letrec_assign2(self): x, f = Const('x'), Const('f') assert_raises(MultiAssignToConstError, eval, letrec([(f, lamda((x,), f(1), assign(f, 1)))], f(2)))
def test_chars(self): x, cs, chars = LogicVar('x'), Var('cs'), MacroVar('chars') x1 = Var('x') eq_(eval(let([(chars, lamda((x1, cs), begin(char(x1), contain(cs, x1))))], parse_text(chars(x, 'a'), 'a'), getvalue(x))), 'a')
def test_callcc(self): k = Var('k') eq_(eval(add(callcc(lamda((k,), k(1))),2)), 3)
def test_letrec_odd_even(self): from util import n, odd, even eq_(eval(letrec([(odd, lamda([n], if_(eq(n,0), 0, even(sub(n,1))))), (even, lamda([n], if_(eq(n,0), 1, odd(sub(n, 1)))))], odd(3))), 1)
def testblock(self): f = Var('f') foo = Var('foo') eq_(eval(block(foo, let([(f, lamda((), exit_block(foo,1)))], mul(2, block(foo, f()))))), 1)
def test_letrec_fac(self): from util import m, n, fac eq_(eval(letrec([(fac, lamda([n], if_(eq(n,1), 1, mul(n, fac(sub(n, 1))))))], fac(3))), 6)
def test_letrec3(self): x, f = Var('x'), Var('f') eq_(eval(letrec([(f, lamda((x,), if_(eq(x,1), 1, f(sub(x,1)))))], f(2))), 1)
def test_lamda(self): x = Const('x') eq_(eval(lamda((x,), 1)(1)), 1) eq_(eval(lamda((x,), 1)(2)), 1) eq_(eval(lamda((x,), x)(2)), 2)
def test_lambda(self): x, y, k = Var('x'), Var('y'), il.Var('k') result = cps(lamda((x,y), 1)) expect = done()(lamda((x, y, k), k(1))) eq_(result, expect)
def test_lamda3(self): x, x1, y, y1, k = Var('x'), Var('x1'), Var('y'), Var('y1'), Var('k') assert_raises(VariableNotBound, alpha, lamda((x, ), x, y))
def test_lamda2(self): x, y = Const('x'), Const('y') eq_(eval(lamda((x, y), add(x, y))(1, 3)), 4)
def test_callcc(self): k = Var('k') eq_(eval(add(callcc(lamda((k, ), k(1))), 2)), 3)
def test_lamda2(self): x, x1, y, y1, k = Var('x'), Var('x1'), Var('y'), Var('y1'), Var('k') eq_(alpha(lamda((x,y), lamda((x,), x, y), x)), lamda((x,y), lamda((x1,), x1, y), x))
def test_lamda(self): x = Const('x') eq_(eval(lamda((x, ), 1)(1)), 1) eq_(eval(lamda((x, ), 1)(2)), 1) eq_(eval(lamda((x, ), x)(2)), 2)
def xtest_letrec2(self): x, f = Var('x'), Var('f') eq_(eval(letrec([(f, lamda((x,), f(1)))], f(2))), 1)
def test_lambda(self): x, y, k = Var('x'), Var('y'), il.Var('k') result = cps(lamda((x, y), 1)) expect = done()(lamda((x, y, k), k(1))) eq_(result, expect)
def test_lamda(self): x, x1, y, y1, k = Var('x'), Var('x1'), Var('y'), Var('y1'), Var('k') eq_(alpha(lamda((x,y), 1)), lamda((x, y), il.Integer(1)))
def xtest_letrec2(self): x, f = Var('x'), Var('f') eq_(eval(letrec([(f, lamda((x, ), f(1)))], f(2))), 1)
def test_lamda3(self): x, x1, y, y1, k = Var('x'), Var('x1'), Var('y'), Var('y1'), Var('k') assert_raises(VariableNotBound, alpha, lamda((x,), x, y))
def test_lamda(self): x, x1, y, y1, k = Var('x'), Var('x1'), Var('y'), Var('y1'), Var('k') eq_(alpha(lamda((x, y), 1)), lamda((x, y), il.Integer(1)))