コード例 #1
0
def test_heado():
    x, y, z = var(), var(), var()
    assert (x, 1) in results(heado(x, (1, 2, 3)))[0].items()
    assert (x, 1) in results(heado(1, (x, 2, 3)))[0].items()
    assert results(heado(x, ())) == ()

    assert run(0, x, heado(x, z), conso(1, y, z)) == (1, )
コード例 #2
0
def lookupo(name, env, t, depth=0, maxdepth=100):
    if depth >= maxdepth:
        return fail

    head = var()
    rest = var()
    # fmt: off
    return conde(
        (heado(head, env), heado(name, head), tailo(rest, head), heado(
            t, rest)),
        (tailo(rest, env), lookupo(name, rest, t, depth + 1, maxdepth)))
コード例 #3
0
def eval_stmto(stmt, env, new_env, depth=0, maxdepth=3):
    logger.info("Evaluating stmt {} to new env {} using old env {}".format(
        ast_dump_if_possible(stmt),
        ast_dump_if_possible(new_env),
        ast_dump_if_possible(env),
    ))
    if depth >= maxdepth:
        return fail

    uuid = str(uuid4())[:4]

    # fmt: off
    goals = conde(
        (
            eq(
                stmt,
                ast.Assign(targets=var('assign_targets_' + uuid),
                           value=var("assign_value_" + uuid))),
            # TODO: Allow for multiple assigns: a, b, = ...
            heado(ast.Name(id=var('assign_lhs_' + uuid), ctx=ast.Store()),
                  var('assign_targets_' + uuid)),
            eval_expro(var("assign_value_" + uuid), env,
                       var("assign_rhs_" + uuid)),
            conso([var("assign_lhs_" + uuid),
                   var("assign_rhs_" + uuid)], env,
                  new_env),  # new_env = [lhs, rhs] + env
        ),
        # Expression statements don't change the environment
        (
            eq(stmt, ast.Expr(value=var("exprbody" + uuid))),  # Expressions
            eq(env, new_env)),
    )
    # fmt: on
    return goals
コード例 #4
0
ファイル: test_goals.py プロジェクト: yusuf-kayyalie/logpy
def test_heado():
    assert (x, 1) in results(heado(x, (1, 2, 3)))[0].items()
    assert (x, 1) in results(heado(1, (x, 2, 3)))[0].items()
    assert results(heado(x, ())) == ()

    assert run(0, x, (heado, x, z), (conso, 1, y, z)) == (1, )
コード例 #5
0
ファイル: test_goals.py プロジェクト: logpy/logpy
def test_heado():
    assert (x, 1) in results(heado(x, (1, 2, 3)))[0].items()
    assert (x, 1) in results(heado(1, (x, 2, 3)))[0].items()
    assert results(heado(x, ())) == ()

    assert run(0, x, (heado, x, z), (conso, 1, y, z)) == (1, )