Ejemplo n.º 1
0
 def _walk_node(n):
     if has_doc_dict(n):
         return _walk_node(list(it.tail(n)))
     else:
         operator = it.head(n)
         rest = it.tail(n)
         return [operator] + f(rest)
Ejemplo n.º 2
0
    def test_tail(self):
        self.assertEqual([1, 2], list(iters.tail([0, 1, 2])))
        self.assertEqual([], list(iters.tail([])))

        def gen():
            yield 1
            yield 2
            yield 3

        self.assertEqual([2, 3], list(iters.tail(gen())))
Ejemplo n.º 3
0
    def test_tail(self):
        self.assertEqual([1,2], list(iters.tail([0,1,2])))
        self.assertEqual([], list(iters.tail([])))

        def gen():
            yield 1 
            yield 2
            yield 3 

        self.assertEqual([2,3], list(iters.tail(gen())))
Ejemplo n.º 4
0
def eval(node):
    """
    Evaluate an s-expression by applying the operator to the rest of the arguments.

    Args:
      node (list): An s-expression list in the form of [operator, arg1, arg2, ...]

    Yields:
      The result of "applying" the operator to the arugments. Will evaluate
      recursively if any of the args are a list.

    Examples:
      >>> eval([>, 0, 1])
      FALSE
    """
    if isinstance(it.head(node), dict):
        return eval(list(it.tail(node)))
    else:
        args = map(fn.recursive_apply(eval), it.tail(node))
        f = operator(it.head(node))
        return apply(f, args)