示例#1
0
    def testTrampoline(self):
        # trampolined factorial
        def fact(n, ans, cont):
            if n < 2:
                return bounce(cont, ans)
            else:
                return bounce(fact, n-1, n*ans, cont)

        ans = pogo_stick(bounce(fact, 5, 1, lambda d:d))
        self.assertEqual(ans, 120)

        ans = pogo_stick(bounce(fact, 1, 1, lambda d:d))
        self.assertEqual(ans, 1)


        # member search
        def memq(target, lst, cont):
            if lst == []:
                return bounce(cont, False)
            elif target == lst[0]:
                return bounce(cont, True)
            else:
                return bounce(memq, target, lst[1:], cont)

        ans = pogo_stick(bounce(memq, 3, [1, 2, 3, 4, 5], lambda d:d))
        self.assertEqual(ans, True)

        ans = pogo_stick(bounce(memq, 3, [1, 2, 4, 5, 6], lambda d:d))
        self.assertEqual(ans, False)
示例#2
0
文件: parser.py 项目: pjhades/Tabris
 def parse(self, tokens):
     """The interface. Returns the list of S-expressions
     generated from the given token list.
     """
     self.sexps = []
     while True:
         if len(tokens) == 0:
             return self.sexps
         self.sexps.append(pogo_stick(bounce(self.parse_sexp, tokens, lambda d:d)))
示例#3
0
文件: tpair.py 项目: pjhades/Tabris
def to_python_list(scmlist):
    return pogo_stick(bounce(_to_python_list, scmlist, [], lambda d:d))
示例#4
0
文件: tpair.py 项目: pjhades/Tabris
def to_str(p):
    return pogo_stick(bounce(_to_str, p, lambda d:d))
示例#5
0
文件: tpair.py 项目: pjhades/Tabris
def from_python_list(pylist):
    return pogo_stick(bounce(_from_python_list, list(reversed(pylist)), NIL, lambda d:d))