src/Pure/Thy/thm_database.ML
author wenzelm
Tue Jul 02 15:45:55 2002 +0200 (2002-07-02)
changeset 13279 8a722689a1c9
parent 11895 73b2c277974f
child 14680 6029e76841fd
permissions -rw-r--r--
removed thms_containing (see pure_thy.ML and proof_context.ML);
clasohm@1132
     1
(*  Title:      Pure/Thy/thm_database.ML
clasohm@1132
     2
    ID:         $Id$
wenzelm@11895
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@11895
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
clasohm@1132
     5
wenzelm@13279
     6
Interface to thm database.
wenzelm@4023
     7
*)
clasohm@1262
     8
wenzelm@6204
     9
signature BASIC_THM_DATABASE =
wenzelm@4023
    10
sig
wenzelm@4023
    11
  val store_thm: string * thm -> thm
wenzelm@7410
    12
  val store_thms: string * thm list -> thm list
wenzelm@4023
    13
end;
clasohm@1132
    14
wenzelm@6204
    15
signature THM_DATABASE =
wenzelm@6204
    16
sig
wenzelm@6204
    17
  include BASIC_THM_DATABASE
wenzelm@7410
    18
  val qed_thms: thm list ref
wenzelm@6204
    19
  val ml_store_thm: string * thm -> unit
wenzelm@7410
    20
  val ml_store_thms: string * thm list -> unit
wenzelm@6204
    21
  val is_ml_identifier: string -> bool
berghofe@11529
    22
  val ml_reserved: string list
wenzelm@6204
    23
end;
wenzelm@6204
    24
wenzelm@3627
    25
structure ThmDatabase: THM_DATABASE =
nipkow@1221
    26
struct
clasohm@1132
    27
wenzelm@4023
    28
(** store theorems **)
clasohm@1132
    29
wenzelm@13279
    30
(* store in theory and perform presentation *)
clasohm@1136
    31
wenzelm@4023
    32
fun store_thm (name, thm) =
wenzelm@7410
    33
  let val thm' = hd (PureThy.smart_store_thms (name, [thm]))
wenzelm@6327
    34
  in Present.theorem name thm'; thm' end;
clasohm@1132
    35
wenzelm@7410
    36
fun store_thms (name, thms) =
wenzelm@7410
    37
  let val thms' = PureThy.smart_store_thms (name, thms)
wenzelm@7410
    38
  in Present.theorems name thms'; thms' end;
wenzelm@7410
    39
clasohm@1262
    40
wenzelm@4023
    41
(* store on ML toplevel *)
wenzelm@4023
    42
wenzelm@7410
    43
val qed_thms: thm list ref = ref [];
clasohm@1262
    44
wenzelm@4023
    45
val ml_reserved =
wenzelm@4023
    46
 ["abstype", "and", "andalso", "as", "case", "do", "datatype", "else",
wenzelm@4023
    47
  "end", "exception", "fn", "fun", "handle", "if", "in", "infix",
wenzelm@4023
    48
  "infixr", "let", "local", "nonfix", "of", "op", "open", "orelse",
wenzelm@4023
    49
  "raise", "rec", "then", "type", "val", "with", "withtype", "while",
wenzelm@4023
    50
  "eqtype", "functor", "include", "sharing", "sig", "signature",
wenzelm@4023
    51
  "struct", "structure", "where"];
clasohm@1262
    52
wenzelm@4023
    53
fun is_ml_identifier name =
wenzelm@4023
    54
  Syntax.is_identifier name andalso not (name mem ml_reserved);
clasohm@1262
    55
wenzelm@7410
    56
fun warn_ml name =
wenzelm@7410
    57
  if is_ml_identifier name then false
wenzelm@7573
    58
  else if name = "" then true
wenzelm@7410
    59
  else (warning ("Cannot bind theorem(s) " ^ quote name ^ " as ML value"); true);
wenzelm@7410
    60
wenzelm@10914
    61
val use_text_verbose = use_text Context.ml_output true;
wenzelm@7854
    62
wenzelm@4023
    63
fun ml_store_thm (name, thm) =
wenzelm@4023
    64
  let val thm' = store_thm (name, thm) in
wenzelm@7410
    65
    if warn_ml name then ()
wenzelm@13279
    66
    else (qed_thms := [thm'];
wenzelm@13279
    67
      use_text_verbose ("val " ^ name ^ " = hd (! ThmDatabase.qed_thms);"))
wenzelm@7410
    68
  end;
wenzelm@7410
    69
wenzelm@7410
    70
fun ml_store_thms (name, thms) =
wenzelm@7410
    71
  let val thms' = store_thms (name, thms) in
wenzelm@7410
    72
    if warn_ml name then ()
wenzelm@7854
    73
    else (qed_thms := thms'; use_text_verbose ("val " ^ name ^ " = ! ThmDatabase.qed_thms;"))
clasohm@1262
    74
  end;
clasohm@1262
    75
wenzelm@4023
    76
clasohm@1132
    77
end;
wenzelm@6204
    78
wenzelm@6204
    79
structure BasicThmDatabase: BASIC_THM_DATABASE = ThmDatabase;
wenzelm@6204
    80
open BasicThmDatabase;