コード例 #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}
コード例 #2
0
ファイル: traverse.py プロジェクト: mrocklin/strategies
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
コード例 #3
0
ファイル: traverse.py プロジェクト: mrocklin/strategies
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
コード例 #4
0
def test_operator():
    assert operator(('add', 1, 2, 3)) == 'add'