Пример #1
0
 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)
Пример #2
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)
Пример #3
0
 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)
Пример #4
0
 def testLoopUntil(self):
     eq_(
         eval(
             tag_loop_label(
                 let([(i, 3)],
                     LoopUntilForm((set(i, sub(i, 1)), prin(i)),
                                   eq(i, 0))))), None)
Пример #5
0
 def test_unwind_protect_loop(self):
   from util import a, i
   eq_(eval(let([(i,3)], 
                block(a, assign(i, sub(i, 1)), 
                         if_(eq(i, 0), 
                           exit_block(a, 1),
                           unwind_protect(continue_block(a), prin(i)))), i)), 0)
Пример #6
0
 def testLoopWhen(self):
     eq_(
         eval(
             tag_loop_label(
                 let([(i, 3)],
                     LoopWhenForm((set(i, sub(i, 1)), prin(i)),
                                  gt(i, 0))))), None)
Пример #7
0
 def testLoopTimes(self):
     eq_(
         eval(
             tag_loop_label(
                 let([(i, 3)],
                     LoopTimesForm(3, (set(i, sub(i, 1)), prin(i)))))),
         None)
Пример #8
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)
Пример #9
0
 def testloop(self):
     from util import a, i
     eq_(
         eval(
             let([(i, 3)],
                 block(a, assign(i, sub(i, 1)),
                       if_(eq(i, 0), exit_block(a, 1), continue_block(a))),
                 i)), 0)
Пример #10
0
 def testloop(self):
   from util import a, i
   eq_(eval(let([(i,3)], 
                block(a, assign(i, sub(i, 1)), 
                         if_(eq(i, 0), 
                             exit_block(a, 1), 
                             continue_block(a))), 
                i)), 0)
Пример #11
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)
Пример #12
0
 def test_unwind_protect_loop(self):
     from util import a, i
     eq_(
         eval(
             let([(i, 3)],
                 block(
                     a, assign(i, sub(i, 1)),
                     if_(eq(i, 0), exit_block(a, 1),
                         unwind_protect(continue_block(a), prin(i)))), i)),
         0)
Пример #13
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)
Пример #14
0
 def test_letrec_rules(self):
     f = Var('f')
     x = Var('x')
     eq_(eval(letrec([(f, rules([[1], 1], [[x], f(sub(x, 1))]))], f(1))),
         1)  # passed
     eq_(eval(letrec([(f, rules([[1], 1], [[x], f(sub(x, 1))]))], f(2))), 1)
Пример #15
0
 def test_arithmetic(self):
   eq_(eval(add(1, 2)), 3) 
   eq_(eval(sub(1, 1)), 0)
   eq_(eval(mul(2, 2)), 4)
   eq_(eval(div(2, 2)), 1)
Пример #16
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)
Пример #17
0
 def test_arithmetic(self):
     eq_(eval(add(1, 2)), 3)
     eq_(eval(sub(1, 1)), 0)
     eq_(eval(mul(2, 2)), 4)
     eq_(eval(div(2, 2)), 1)
Пример #18
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)
Пример #19
0
 def test_letrec_rules(self):
   f = Var('f')
   x = Var('x')
   eq_(eval(letrec([(f, rules([[1], 1],[[x],f(sub(x,1))]))], f(1))), 1) # passed
   eq_(eval(letrec([(f, rules([[1], 1],[[x],f(sub(x,1))]))], f(2))), 1)
Пример #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)
Пример #21
0
 def testLoopTimes(self):
   eq_(eval(tag_loop_label(let([(i,3)], LoopTimesForm(3, (set(i, sub(i, 1)), prin(i)))))), None)
Пример #22
0
 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)
Пример #23
0
 def testLoopUntil(self):
   eq_(eval(tag_loop_label(let([(i,3)], LoopUntilForm((set(i, sub(i, 1)), prin(i)), 
                                    eq(i,0))))), None)
Пример #24
0
 def testLoopWhen(self):
   eq_(eval(tag_loop_label(let([(i,3)], LoopWhenForm((set(i, sub(i, 1)), prin(i)), 
                                    gt(i,0))))), None)
Пример #25
0
 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)
Пример #26
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)