Example #1
0
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}
Example #2
0
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
Example #3
0
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
Example #4
0
def test_arguments():
    assert arguments(('add', 1, 2, 3)) == (1, 2, 3)