Exemple #1
0
 def test_letrec_odd_even(self):
     from util import n
     odd, even = MacroVar('odd'), MacroVar('even')
     eq_(
         eval(
             letrec([(odd, macro([n], if_(eq(n, 0), 0, even(sub(n, 1))))),
                     (even, macro([n], if_(eq(n, 0), 1, odd(sub(n, 1)))))],
                    odd(3))), 1)
Exemple #2
0
 def testembedvar2(self):
     e, e2, f, g, h = Var('e'), Var('e2'), Var('f'), Var('g'), Var('h')
     eq_(
         eval(
             letrec([(f, macro([[cons(1, e2)], g(e2)])),
                     (g, function([[e], h(e)])),
                     (h, function([[1], True]))], f(e), e)), cons(1, 1))
Exemple #3
0
 def test_kleene2(self):
     f, kleene = MacroVar('f'), MacroVar('kleene')
     _ = DummyVar('_')
     item = Var('item')
     fun = macro((item, ),
                 letrec([(f, macrorules(((), item, f()), ((), nullword)))],
                        f()))
     eq_(eval(let([(kleene, fun)], set_text('ab'), kleene(char(_)))), True)
Exemple #4
0
 def test_letrec_fac(self):
     from util import m, n
     fac = MacroVar('fac')
     eq_(
         eval(
             letrec([
                 (fac, macro([n], if_(eq(n, 1), 1, mul(n, fac(sub(n, 1))))))
             ], fac(3))), 6)
Exemple #5
0
 def test_macro6(self):
     n, act, ntimes = Var('n'), Var('act'), MacroVar('ntimes')
     eq_(
         eval(
             letrec([(ntimes,
                      macro((n, act),
                            if_(eq(n, 0), 1,
                                begin(act, ntimes(sub(n, 1), act)))))],
                    ntimes(3, println(1)))), 1)
Exemple #6
0
 def test_kleene1(self):
   f, kleene = MacroVar('f'), MacroVar('kleene')
   item = Var('item')
   fun = macro((item,),  
           letrec([(f, macrorules(
             ((), item, f()),
             ((), nullword)))], 
                f()))
   eq_(eval(let([(kleene, fun)], set_text('aa'), kleene(char('a')))), True)
Exemple #7
0
 def test_macro5(self):
     x, y, f = Const('x'), Const('y'), MacroVar('f')
     eq_(eval(let([(f, macro((x, y), y, x, 1))], f(println(1), prin(2)))),
         1)
Exemple #8
0
 def test_macro3(self):
     x, y = Const('x'), Const('y')
     eq_(eval(macro((x, y), y, x, 1)(println(1), prin(2))), 1)
Exemple #9
0
 def test_macro2(self):
     x, y = Var('x'), Var('y')
     eq_(eval(macro((x, y), add(x, y))(1, 3)), 4)
Exemple #10
0
 def test_macro6(self):
   n, act, ntimes = Var('n'), Var('act'), MacroVar('ntimes')
   eq_(eval(letrec([(ntimes, macro((n, act), 
                   if_(eq(n, 0), 1, 
                       begin(act, ntimes(sub(n, 1), act)))))], 
                   ntimes(3, println(1)))), 1)
Exemple #11
0
 def testletdouble1(self):
     x, f = Var('x'), MacroVar('f')
     eq_(eval(let([(f, macro([x], add(x, x)))], f(1))), 2)
Exemple #12
0
 def test_letrec_assign2(self):
     x, f = Const('x'), Const('f')
     assert_raises(MultiAssignToConstError, eval,
                   letrec([(f, macro((x, ), f(1), assign(f, 1)))], f(2)))
Exemple #13
0
 def test_letrec_fac(self):
   from util import m, n
   fac = MacroVar('fac')
   eq_(eval(letrec([(fac, macro([n], if_(eq(n,1), 1, mul(n, fac(sub(n, 1))))))],
                 fac(3))), 6)
Exemple #14
0
 def testletdouble2(self):
   x, f = Const('x'), ConstMacroVar('f')
   eq_(eval(let([(f, macro([x], add(x, x)))], f(1))), 2)
Exemple #15
0
 def testletdouble1(self):
   x, f = Var('x'), MacroVar('f')
   eq_(eval(let([(f, macro([x], add(x, x)))], f(1))), 2)
Exemple #16
0
 def test_letrec3(self):
   x, f = Var('x'), MacroVar('f')
   eq_(eval(letrec([(f, macro((x,), if_(eq(x,1), 1, f(sub(x,1)))))], f(2))), 1)
Exemple #17
0
 def test_letrec_assign2(self):
   x, f = Const('x'), Const('f')
   assert_raises(MultiAssignToConstError, eval,
                 letrec([(f, macro((x,), f(1), assign(f, 1)))], f(2)))
Exemple #18
0
 def xtest_letrec2(self):
   x, f = Var('x'), MacroVar('f')
   eq_(eval(letrec([(f, macro((x,), f(1)))], f(2))), 1)
Exemple #19
0
 def xtest_letrec2(self):
     x, f = Var('x'), MacroVar('f')
     eq_(eval(letrec([(f, macro((x, ), f(1)))], f(2))), 1)
Exemple #20
0
 def test_letrec_odd_even(self):
   from util import n
   odd, even  = MacroVar('odd'), MacroVar('even')  
   eq_(eval(letrec([(odd, macro([n], if_(eq(n,0), 0, even(sub(n,1))))),
                   (even, macro([n], if_(eq(n,0), 1, odd(sub(n, 1)))))],
                 odd(3))), 1)
Exemple #21
0
 def test_letrec3(self):
     x, f = Var('x'), MacroVar('f')
     eq_(
         eval(
             letrec([(f, macro((x, ), if_(eq(x, 1), 1, f(sub(x, 1)))))],
                    f(2))), 1)
Exemple #22
0
 def testembedvar2(self):
   e, e2, f, g, h = Var('e'), Var('e2'), Var('f'), Var('g'), Var('h')
   eq_(eval(letrec([(f, macro([[cons(1, e2)], g(e2)])),
                    (g, function([[e], h(e)])),
                    (h, function([[1], True]))],
               f(e), e)), cons(1, 1))
Exemple #23
0
 def testletdouble2(self):
     x, f = Const('x'), ConstMacroVar('f')
     eq_(eval(let([(f, macro([x], add(x, x)))], f(1))), 2)
Exemple #24
0
 def test_macro3(self):
   x, y = Const('x'), Const('y')
   eq_(eval(macro((x, y), y, x, 1)(println(1), prin(2))), 1)
Exemple #25
0
 def test_macro2(self):
   x, y = Var('x'), Var('y')
   eq_(eval(macro((x, y), add(x, y))(1, 3)), 4)
Exemple #26
0
 def test_macro5(self):
   x, y, f = Const('x'), Const('y'), MacroVar('f')
   eq_(eval(let([(f, macro((x, y), y, x, 1))], f(println(1), prin(2)))), 1)
Exemple #27
0
 def test_macro(self):
     x, y = Var('x'), Var('y')
     eq_(eval(macro((x, ), 1)(1)), 1)
     eq_(eval(macro((x, ), 1)(2)), 1)
     eq_(eval(macro((x, ), x)(2)), 2)
Exemple #28
0
 def test_macro(self):
   x, y = Var('x'), Var('y')
   eq_(eval(macro((x,), 1)(1)), 1)
   eq_(eval(macro((x,), 1)(2)), 1)
   eq_(eval(macro((x,), x)(2)), 2)