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