def test_unifiable_with_term(): add = Op('add') t = MyTerm(add, (1, 2)) assert arguments(t) == (1, 2) assert operator(t) == add assert term(operator(t), arguments(t)) == t x = var('x') assert unify(MyTerm(add, (1, x)), MyTerm(add, (1, 2)), {}) == {x: 2}
def sall(rule, expr): """ Strategic all - apply rule to args """ try: op = operator(expr) children = arguments(expr) if children: children = list(map(rule, children)) return term(op, children) except NotImplementedError: return expr
def test_operator(): assert operator(('add', 1, 2, 3)) == 'add'