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, )
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)))
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
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, )