def test_chain(): rl = chain(posdec, posdec) assert rl(5) == 3 assert rl(1) == 0
def bottom_up(rule, fns=basic_fns): """ Apply a rule down a tree running it on the bottom nodes first """ return chain(lambda expr: sall(bottom_up(rule, fns), fns)(expr), rule)
def top_down(rule, fns=basic_fns): """ Apply a rule down a tree running it on the top nodes first """ return chain(rule, lambda expr: sall(top_down(rule, fns), fns)(expr))