1 (* Title: Pure/ML/ml_thms.ML
4 Isar theorem values within ML.
9 val the_thms: Proof.context -> int -> thm list
10 val the_thm: Proof.context -> int -> thm
13 structure ML_Thms: ML_THMS =
16 (* auxiliary facts table *)
18 structure AuxFacts = ProofDataFun
20 type T = thm list Inttab.table;
21 fun init _ = Inttab.empty;
24 val put_thms = AuxFacts.map o Inttab.update;
26 fun the_thms ctxt name = the (Inttab.lookup (AuxFacts.get ctxt) name);
27 fun the_thm ctxt name = the_single (the_thms ctxt name);
29 fun thm_bind kind a i =
30 "val " ^ a ^ " = ML_Thms.the_" ^ kind ^
31 " (ML_Context.the_local_context ()) " ^ string_of_int i ^ ";\n";
36 fun thm_antiq kind scan = ML_Context.add_antiq kind
37 (fn _ => scan >> (fn ths => fn {struct_name, background} =>
40 val (a, background') = background
41 |> ML_Antiquote.variant kind ||> put_thms (i, ths);
42 val ml = (thm_bind kind a i, struct_name ^ "." ^ a);
43 in (K ml, background') end));
45 val _ = thm_antiq "thm" (Attrib.thm >> single);
46 val _ = thm_antiq "thms" Attrib.thms;
51 val by = Args.$$$ "by";
52 val goal = Scan.unless (Scan.lift by) Args.prop;
54 val _ = ML_Context.add_antiq "lemma"
55 (fn pos => Args.context -- Args.mode "open" -- Scan.repeat1 goal --
56 Scan.lift (by |-- Method.parse -- Scan.option Method.parse) >>
57 (fn (((ctxt, is_open), props), methods) => fn {struct_name, background} =>
61 Goal.norm_result #> Thm.default_position pos #> not is_open ? Thm.close_derivation;
62 fun after_qed [res] goal_ctxt =
63 put_thms (i, map prep_result (ProofContext.export goal_ctxt ctxt res)) goal_ctxt;
65 |> Proof.theorem_i NONE after_qed [map (rpair []) props]
66 |> Proof.global_terminal_proof methods;
67 val (a, background') = background
68 |> ML_Antiquote.variant "lemma" ||> put_thms (i, the_thms ctxt' i);
69 val ml = (thm_bind (if length props = 1 then "thm" else "thms") a i, struct_name ^ "." ^ a);
70 in (K ml, background') end));