src/Pure/pure_thy.ML
changeset 9564 391f3ee75b1e
parent 9534 0d14a9e7930c
child 9808 4e47e40c0ac5
equal deleted inserted replaced
9563:216d053992a5 9564:391f3ee75b1e
    23 end;
    23 end;
    24 
    24 
    25 signature PURE_THY =
    25 signature PURE_THY =
    26 sig
    26 sig
    27   include BASIC_PURE_THY
    27   include BASIC_PURE_THY
       
    28   val get_thms_closure: theory -> xstring -> thm list
       
    29   val single_thm: string -> thm list -> thm
    28   val cond_extern_thm_sg: Sign.sg -> string -> xstring
    30   val cond_extern_thm_sg: Sign.sg -> string -> xstring
    29   val thms_containing: theory -> string list -> (string * thm) list
    31   val thms_containing: theory -> string list -> (string * thm) list
    30   val store_thm: (bstring * thm) * theory attribute list -> theory -> theory * thm
    32   val store_thm: (bstring * thm) * theory attribute list -> theory -> theory * thm
    31   val smart_store_thms: (bstring * thm list) -> thm list
    33   val smart_store_thms: (bstring * thm list) -> thm list
    32   val forall_elim_var: int -> thm -> thm
    34   val forall_elim_var: int -> thm -> thm
   113 
   115 
   114 
   116 
   115 
   117 
   116 (** retrieve theorems **)
   118 (** retrieve theorems **)
   117 
   119 
   118 (* get_thms etc. *)
   120 (* selections *)
   119 
   121 
   120 fun lookup_thms name thy =
   122 fun the_thms _ (Some thms) = thms
   121   let val ref {space, thms_tab, ...} = get_theorems thy
   123   | the_thms name None = error ("Unknown theorem(s) " ^ quote name);
   122   in Symtab.lookup (thms_tab, NameSpace.intern space name) end;
   124 
   123 
   125 fun single_thm _ [thm] = thm
   124 fun get_thms thy name =
   126   | single_thm name _ = error ("Single theorem expected " ^ quote name);
   125   (case get_first (lookup_thms name) (thy :: Theory.ancestors_of thy) of
   127 
   126     None => raise THEORY ("Unknown theorem(s) " ^ quote name, [thy])
   128 
   127   | Some thms => map (Thm.transfer thy) thms);
   129 (* get_thms_closure -- statically scoped *)
   128 
   130 
   129 fun get_thm thy name =
   131 (*beware of proper order of evaluation!*)
   130   (case get_thms thy name of
   132 
   131     [thm] => thm
   133 fun lookup_thms thy =
   132   | _ => raise THEORY ("Single theorem expected " ^ quote name, [thy]));
   134   let
       
   135     val sg_ref = Sign.self_ref (Theory.sign_of thy);
       
   136     val ref {space, thms_tab, ...} = get_theorems thy;
       
   137   in
       
   138     fn name =>
       
   139       apsome (map (Thm.transfer_sg (Sign.deref sg_ref)))  	(*semi-dynamic identity*)
       
   140       (Symtab.lookup (thms_tab, NameSpace.intern space name))   (*static content*)
       
   141   end;
       
   142 
       
   143 fun get_thms_closure thy =
       
   144   let val closures = map lookup_thms (thy :: Theory.ancestors_of thy)
       
   145   in fn name => the_thms name (get_first (fn f => f name) closures) end;
       
   146 
       
   147 
       
   148 (* get_thm etc. *)
       
   149 
       
   150 fun get_thms theory name =
       
   151   get_first (fn thy => lookup_thms thy name) (theory :: Theory.ancestors_of theory)
       
   152   |> the_thms name |> map (Thm.transfer theory);
   133 
   153 
   134 fun get_thmss thy names = flat (map (get_thms thy) names);
   154 fun get_thmss thy names = flat (map (get_thms thy) names);
       
   155 fun get_thm thy name = single_thm name (get_thms thy name);
   135 
   156 
   136 
   157 
   137 (* thms_of *)
   158 (* thms_of *)
   138 
   159 
   139 fun attach_name thm = (Thm.name_of_thm thm, thm);
   160 fun attach_name thm = (Thm.name_of_thm thm, thm);