<commit_before>/*
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.

Author: <NAME>
*/
#include "library/util.h"
#include "library/constants.h"
#include "library/vm/vm_expr.h"
#include "library/tactic/tactic_state.h"

namespace lean {
vm_obj change(expr const & e, tactic_state const & s) {
    try {
        optional<metavar_decl> g = s.get_main_goal_decl();
        if (!g) return mk_no_goals_exception(s);
        type_context ctx         = mk_type_context_for(s);
        if (ctx.is_def_eq(e, g->get_type())) {
            auto mctx    = ctx.mctx();
            expr new_M   = mctx.mk_metavar_decl(g->get_context(), e);
            /*
               We use the proof term

                  (@id_locked (g->get_type()) new_M)

               to create a "checkpoint". See discussion at issue #1260
            */
            level lvl = get_level(ctx, g->get_type());
            expr  pr  = mk_app(mk_constant(get_id_locked_name(), {lvl}), g->get_type(), new_M);
            mctx.assign(head(s.goals()), pr);
            list<expr> new_gs(new_M, tail(s.goals()));
            return mk_tactic_success(set_mctx_goals(s, mctx, new_gs));
        } else {
            auto thunk = [=]() {
                format m("tactic.change failed, given type");
                m += pp_indented_expr(s, e);
                m += format("is not definitionally equal to");
                m += pp_indented_expr(s, g->get_type());
                return m;
            };
            return mk_tactic_exception(thunk, s);
        }
    } catch (exception & e) {
        return mk_tactic_exception(e, s);
    }
}

vm_obj tactic_change(vm_obj const & e, vm_obj const & s) {
    return change(to_expr(e), to_tactic_state(s));
}

void initialize_change_tactic() {
    DECLARE_VM_BUILTIN(name({"tactic", "change"}),   tactic_change);
}

void finalize_change_tactic() {
}
}
<commit_msg>chore(library/tactic/change_tactic.cpp): better formatting for error message<commit_after>/*
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.

Author: <NAME>
*/
#include "library/util.h"
#include "library/constants.h"
#include "library/vm/vm_expr.h"
#include "library/tactic/tactic_state.h"

namespace lean {
vm_obj change(expr const & e, tactic_state const & s) {
    try {
        optional<metavar_decl> g = s.get_main_goal_decl();
        if (!g) return mk_no_goals_exception(s);
        type_context ctx         = mk_type_context_for(s);
        if (ctx.is_def_eq(e, g->get_type())) {
            auto mctx    = ctx.mctx();
            expr new_M   = mctx.mk_metavar_decl(g->get_context(), e);
            /*
               We use the proof term

                  (@id_locked (g->get_type()) new_M)

               to create a "checkpoint". See discussion at issue #1260
            */
            level lvl = get_level(ctx, g->get_type());
            expr  pr  = mk_app(mk_constant(get_id_locked_name(), {lvl}), g->get_type(), new_M);
            mctx.assign(head(s.goals()), pr);
            list<expr> new_gs(new_M, tail(s.goals()));
            return mk_tactic_success(set_mctx_goals(s, mctx, new_gs));
        } else {
            auto thunk = [=]() {
                format m("tactic.change failed, given type");
                m += pp_indented_expr(s, e);
                m += line() + format("is not definitionally equal to");
                m += pp_indented_expr(s, g->get_type());
                return m;
            };
            return mk_tactic_exception(thunk, s);
        }
    } catch (exception & e) {
        return mk_tactic_exception(e, s);
    }
}

vm_obj tactic_change(vm_obj const & e, vm_obj const & s) {
    return change(to_expr(e), to_tactic_state(s));
}

void initialize_change_tactic() {
    DECLARE_VM_BUILTIN(name({"tactic", "change"}),   tactic_change);
}

void finalize_change_tactic() {
}
}

{'fraction_non_alphanumeric': 0.1308623298033283, 'fraction_numerical': 0.005042864346949067, 'mean_word_length': 2.342038753159225, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3295012', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1308, 'n_words': 294}