def test_match_pattern_var(): # pylint: disable=missing-docstring term = Term('f', [Var('x'), 2, 3], False) res = term.match(Var('Y')) exp = {'Y': term} assert res == exp
def test_str_non_static(): # pylint: disable=missing-docstring res = str(Term('f', [Var('x'), 2, 3], False)) exp = "f(x, 2, 3)" assert res == exp
def test_subst_term(): # pylint: disable=missing-docstring res = subst(Term('f', [Var('x'), 2, 3], False), {'x': 11}) exp = Term('f', [11, 2, 3], False) assert not exp.match(res)
def test_subst_other_var(): # pylint: disable=missing-docstring res = subst(Var('y'), {'x': 11}) exp = Var('y') assert res == exp
def test_subst_var_ok(): # pylint: disable=missing-docstring res = subst(Var('x'), {'x': 11}) exp = 11 assert res == exp
"""Function composition""" return Fun(fun.compose, [fun_f, fun_g]) def curry(fun_f): """Currying""" return Fun(fun.curry, [fun_f]) def uncurry(fun_f): """Uncurrying""" return Fun(fun.uncurry, [fun_f]) _IDT_COMPOSE_LEFT = \ Rule(left=compose(idt, Var('fun_f')), right=Var('fun_f'), name="idt neutral compose left", type=Fun ) _IDT_COMPOSE_RIGHT = \ Rule(left=compose(Var('fun_f'), idt), right=Var('fun_f'), name="idt neutral compose right", type=Fun ) _CURRY_UNCURRY = \ Rule(left=curry(uncurry(Var('fun_f'))), right=Var('fun_f'),
def raw(lst): return SList("__raw__", [lst]) @staticmethod def init(value_at, size): return SList('init', ['SList', value_at, size]) def __getattr__(self, item): def call_f(*args): return SList(item, [self] + list(args), False) return call_f _MAP_MAP = \ Rule(left=Term('map', [Term('map', [Var('PL'), Var('f')]), Var('g')], False), right=Term('map', [Var('PL'), compose(Var('f'), Var('g'))], False), name="map map", type=_List) _MAP_REDUCE = \ Rule(left=Term('reduce', [Term('map', [Var('PL'), Var('f')]), Var('binary_op')], False), right=Term('map_reduce', [Var('PL'), Var('f'), Var('binary_op')], False), name="map reduce", type=_List) _ZIP_MAP = \ Rule(left=Term('map', [Term('zip', [Var('PL1'), Var('PL2')]), Var('f')], False), right=Term('map2', [Var('PL1'), curry(Var('f')), Var('PL2')], False), name="zip_map", type=_List)