src/Pure/Thy/context.ML
author nipkow
Thu, 26 Nov 1998 12:18:08 +0100
changeset 5974 6acf3ff0f486
parent 5249 9d7e6f7110ef
child 6017 dbb33359a7ab
permissions -rw-r--r--
Added filter_prems_tac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4338
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/context.ML
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
     4
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
     5
Global contexts: session and theory.
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
     6
*)
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
     7
4486
48e4fbc03b7c added >> : (theory -> theory) -> unit;
wenzelm
parents: 4364
diff changeset
     8
signature BASIC_CONTEXT =
4338
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
     9
sig
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    10
  val context: theory -> unit
5049
bde086cfa597 removed Thy;
wenzelm
parents: 5042
diff changeset
    11
  val the_context: unit -> theory
5059
dcdb21e53537 renamed Thm(s) back to thm(s);
wenzelm
parents: 5049
diff changeset
    12
  val thm: xstring -> thm
dcdb21e53537 renamed Thm(s) back to thm(s);
wenzelm
parents: 5049
diff changeset
    13
  val thms: xstring -> thm list
4914
119d5f5767a4 added Goal, Goalw;
wenzelm
parents: 4843
diff changeset
    14
  val Goal: string -> thm list
119d5f5767a4 added Goal, Goalw;
wenzelm
parents: 4843
diff changeset
    15
  val Goalw: thm list -> string -> thm list
5249
9d7e6f7110ef added Open_locale, Close_locale;
wenzelm
parents: 5059
diff changeset
    16
  val Open_locale: xstring -> unit
9d7e6f7110ef added Open_locale, Close_locale;
wenzelm
parents: 5059
diff changeset
    17
  val Close_locale: unit -> unit
4338
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    18
end;
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    19
4486
48e4fbc03b7c added >> : (theory -> theory) -> unit;
wenzelm
parents: 4364
diff changeset
    20
signature CONTEXT =
48e4fbc03b7c added >> : (theory -> theory) -> unit;
wenzelm
parents: 4364
diff changeset
    21
sig
48e4fbc03b7c added >> : (theory -> theory) -> unit;
wenzelm
parents: 4364
diff changeset
    22
  include BASIC_CONTEXT
5031
e2280a1eadb2 tuned exports;
wenzelm
parents: 5027
diff changeset
    23
  val get_session: unit -> string list
e2280a1eadb2 tuned exports;
wenzelm
parents: 5027
diff changeset
    24
  val add_session: string -> unit
e2280a1eadb2 tuned exports;
wenzelm
parents: 5027
diff changeset
    25
  val reset_session: unit -> unit
4925
53900a320a87 added welcome;
wenzelm
parents: 4914
diff changeset
    26
  val welcome: unit -> string
5031
e2280a1eadb2 tuned exports;
wenzelm
parents: 5027
diff changeset
    27
  val get_context: unit -> theory option
e2280a1eadb2 tuned exports;
wenzelm
parents: 5027
diff changeset
    28
  val set_context: theory option -> unit
e2280a1eadb2 tuned exports;
wenzelm
parents: 5027
diff changeset
    29
  val reset_context: unit -> unit
4486
48e4fbc03b7c added >> : (theory -> theory) -> unit;
wenzelm
parents: 4364
diff changeset
    30
  val >> : (theory -> theory) -> unit
48e4fbc03b7c added >> : (theory -> theory) -> unit;
wenzelm
parents: 4364
diff changeset
    31
end;
48e4fbc03b7c added >> : (theory -> theory) -> unit;
wenzelm
parents: 4364
diff changeset
    32
4338
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    33
structure Context: CONTEXT =
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    34
struct
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    35
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    36
4843
df709de137af added thm, thms;
wenzelm
parents: 4486
diff changeset
    37
(** session **)
4338
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    38
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    39
val current_session = ref ([]: string list);
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    40
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    41
fun get_session () = ! current_session;
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    42
fun add_session s = current_session := ! current_session @ [s];
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    43
fun reset_session () = current_session := [];
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    44
4925
53900a320a87 added welcome;
wenzelm
parents: 4914
diff changeset
    45
fun welcome () =
53900a320a87 added welcome;
wenzelm
parents: 4914
diff changeset
    46
  "Welcome to Isabelle/" ^
53900a320a87 added welcome;
wenzelm
parents: 4914
diff changeset
    47
    (case get_session () of [] => "Pure" | ss => space_implode "/" ss) ^
53900a320a87 added welcome;
wenzelm
parents: 4914
diff changeset
    48
    " (" ^ version ^ ")";
53900a320a87 added welcome;
wenzelm
parents: 4914
diff changeset
    49
4338
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    50
4843
df709de137af added thm, thms;
wenzelm
parents: 4486
diff changeset
    51
df709de137af added thm, thms;
wenzelm
parents: 4486
diff changeset
    52
(** theory context **)
4338
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    53
5027
4b1fd9813003 get_context renamed to the_context;
wenzelm
parents: 4925
diff changeset
    54
local
4b1fd9813003 get_context renamed to the_context;
wenzelm
parents: 4925
diff changeset
    55
  val current_theory = ref (None: theory option);
4b1fd9813003 get_context renamed to the_context;
wenzelm
parents: 4925
diff changeset
    56
in
4b1fd9813003 get_context renamed to the_context;
wenzelm
parents: 4925
diff changeset
    57
  fun get_context () = ! current_theory;
4b1fd9813003 get_context renamed to the_context;
wenzelm
parents: 4925
diff changeset
    58
  fun set_context opt_thy = current_theory := opt_thy;
4b1fd9813003 get_context renamed to the_context;
wenzelm
parents: 4925
diff changeset
    59
end;
4338
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    60
5027
4b1fd9813003 get_context renamed to the_context;
wenzelm
parents: 4925
diff changeset
    61
fun the_context () =
4b1fd9813003 get_context renamed to the_context;
wenzelm
parents: 4925
diff changeset
    62
  (case get_context () of
4b1fd9813003 get_context renamed to the_context;
wenzelm
parents: 4925
diff changeset
    63
    Some thy => thy
4364
ab73573067d6 added reset_context;
wenzelm
parents: 4338
diff changeset
    64
  | _ => error "Unknown theory context");
ab73573067d6 added reset_context;
wenzelm
parents: 4338
diff changeset
    65
5027
4b1fd9813003 get_context renamed to the_context;
wenzelm
parents: 4925
diff changeset
    66
fun context thy = set_context (Some thy);
4b1fd9813003 get_context renamed to the_context;
wenzelm
parents: 4925
diff changeset
    67
fun reset_context () = set_context None;
4338
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    68
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    69
4843
df709de137af added thm, thms;
wenzelm
parents: 4486
diff changeset
    70
(* map context *)
df709de137af added thm, thms;
wenzelm
parents: 4486
diff changeset
    71
4486
48e4fbc03b7c added >> : (theory -> theory) -> unit;
wenzelm
parents: 4364
diff changeset
    72
nonfix >>;
5027
4b1fd9813003 get_context renamed to the_context;
wenzelm
parents: 4925
diff changeset
    73
fun >> f = set_context (Some (f (the_context ())));
4486
48e4fbc03b7c added >> : (theory -> theory) -> unit;
wenzelm
parents: 4364
diff changeset
    74
48e4fbc03b7c added >> : (theory -> theory) -> unit;
wenzelm
parents: 4364
diff changeset
    75
4843
df709de137af added thm, thms;
wenzelm
parents: 4486
diff changeset
    76
(* retrieve thms *)
df709de137af added thm, thms;
wenzelm
parents: 4486
diff changeset
    77
5249
9d7e6f7110ef added Open_locale, Close_locale;
wenzelm
parents: 5059
diff changeset
    78
fun thm name = Locale.get_thm (the_context ()) name;
9d7e6f7110ef added Open_locale, Close_locale;
wenzelm
parents: 5059
diff changeset
    79
fun thms name = Locale.get_thms (the_context ()) name;
4843
df709de137af added thm, thms;
wenzelm
parents: 4486
diff changeset
    80
df709de137af added thm, thms;
wenzelm
parents: 4486
diff changeset
    81
4914
119d5f5767a4 added Goal, Goalw;
wenzelm
parents: 4843
diff changeset
    82
(* shortcut goal commands *)
119d5f5767a4 added Goal, Goalw;
wenzelm
parents: 4843
diff changeset
    83
5042
1f077d63a909 Changed and changed back.
nipkow
parents: 5031
diff changeset
    84
fun Goal s = Goals.atomic_goal (the_context ()) s;
1f077d63a909 Changed and changed back.
nipkow
parents: 5031
diff changeset
    85
fun Goalw thms s = Goals.atomic_goalw (the_context ()) thms s;
4914
119d5f5767a4 added Goal, Goalw;
wenzelm
parents: 4843
diff changeset
    86
119d5f5767a4 added Goal, Goalw;
wenzelm
parents: 4843
diff changeset
    87
5249
9d7e6f7110ef added Open_locale, Close_locale;
wenzelm
parents: 5059
diff changeset
    88
(* scope manipulation *)
9d7e6f7110ef added Open_locale, Close_locale;
wenzelm
parents: 5059
diff changeset
    89
9d7e6f7110ef added Open_locale, Close_locale;
wenzelm
parents: 5059
diff changeset
    90
fun Open_locale xname = (Locale.open_locale xname (the_context ()); ());
9d7e6f7110ef added Open_locale, Close_locale;
wenzelm
parents: 5059
diff changeset
    91
fun Close_locale () = (Locale.close_locale (the_context ()); ());
9d7e6f7110ef added Open_locale, Close_locale;
wenzelm
parents: 5059
diff changeset
    92
9d7e6f7110ef added Open_locale, Close_locale;
wenzelm
parents: 5059
diff changeset
    93
4338
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    94
end;
68619c232262 Global contexts: session and theory.
wenzelm
parents:
diff changeset
    95
4486
48e4fbc03b7c added >> : (theory -> theory) -> unit;
wenzelm
parents: 4364
diff changeset
    96
48e4fbc03b7c added >> : (theory -> theory) -> unit;
wenzelm
parents: 4364
diff changeset
    97
structure BasicContext: BASIC_CONTEXT = Context;
48e4fbc03b7c added >> : (theory -> theory) -> unit;
wenzelm
parents: 4364
diff changeset
    98
open BasicContext;