예제 #1
0
    def test_apply(self):
        def add(x, y):
            return x + y

        self.assertEqual(apply(add, [1, 2])[0], 3)
        addclosure = interp(["fun", ["x", "y"], ["+", "x", "y"]],
                            topLevelEnv)[0]
        self.assertEqual(apply(addclosure, [1, 2])[0], 3)
예제 #2
0
def racket_foldr(function, base, lst):
    acc = base
    for elem in lst[::-1]:
        acc = racython.apply(function, [elem, acc])[0]
    return acc
예제 #3
0
def racket_foldl(function, base, lst):
    return reduce(lambda x, acc: racython.apply(function, [x, acc])[0], lst,
                  base)
예제 #4
0
def racket_filter(function, lst):
    return list(filter(lambda x: racython.apply(function, [x])[0], lst))
예제 #5
0
def racket_map(function, list):
    return [racython.apply(function, [x])[0] for x in list]
예제 #6
0
def racket_buildList(num, func):
    return [racython.apply(func, [x])[0] for x in range(num)]
예제 #7
0
파일: testing.py 프로젝트: kamath/racython
 def test_apply(self):
     def add(x,y):
         return x+y
     self.assertEqual(apply(add, [1, 2])[0], 3)
     addClosure = eval(["lambda", ["x", "y"], ["+", "x", "y"]], topLevelEnv)[0]
     self.assertEqual(apply(addClosure, [1, 2])[0], 3)