4338
|
1 |
(* Title: Pure/Thy/context.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Markus Wenzel, TU Muenchen
|
|
4 |
|
|
5 |
Global contexts: session and theory.
|
|
6 |
*)
|
|
7 |
|
4486
|
8 |
signature BASIC_CONTEXT =
|
4338
|
9 |
sig
|
|
10 |
val context: theory -> unit
|
5049
|
11 |
val the_context: unit -> theory
|
5059
|
12 |
val thm: xstring -> thm
|
|
13 |
val thms: xstring -> thm list
|
4914
|
14 |
val Goal: string -> thm list
|
|
15 |
val Goalw: thm list -> string -> thm list
|
4338
|
16 |
end;
|
|
17 |
|
4486
|
18 |
signature CONTEXT =
|
|
19 |
sig
|
|
20 |
include BASIC_CONTEXT
|
5031
|
21 |
val get_session: unit -> string list
|
|
22 |
val add_session: string -> unit
|
|
23 |
val reset_session: unit -> unit
|
4925
|
24 |
val welcome: unit -> string
|
5031
|
25 |
val get_context: unit -> theory option
|
|
26 |
val set_context: theory option -> unit
|
|
27 |
val reset_context: unit -> unit
|
4486
|
28 |
val >> : (theory -> theory) -> unit
|
|
29 |
end;
|
|
30 |
|
4338
|
31 |
structure Context: CONTEXT =
|
|
32 |
struct
|
|
33 |
|
|
34 |
|
4843
|
35 |
(** session **)
|
4338
|
36 |
|
|
37 |
val current_session = ref ([]: string list);
|
|
38 |
|
|
39 |
fun get_session () = ! current_session;
|
|
40 |
fun add_session s = current_session := ! current_session @ [s];
|
|
41 |
fun reset_session () = current_session := [];
|
|
42 |
|
4925
|
43 |
fun welcome () =
|
|
44 |
"Welcome to Isabelle/" ^
|
|
45 |
(case get_session () of [] => "Pure" | ss => space_implode "/" ss) ^
|
|
46 |
" (" ^ version ^ ")";
|
|
47 |
|
4338
|
48 |
|
4843
|
49 |
|
|
50 |
(** theory context **)
|
4338
|
51 |
|
5027
|
52 |
local
|
|
53 |
val current_theory = ref (None: theory option);
|
|
54 |
in
|
|
55 |
fun get_context () = ! current_theory;
|
|
56 |
fun set_context opt_thy = current_theory := opt_thy;
|
|
57 |
end;
|
4338
|
58 |
|
5027
|
59 |
fun the_context () =
|
|
60 |
(case get_context () of
|
|
61 |
Some thy => thy
|
4364
|
62 |
| _ => error "Unknown theory context");
|
|
63 |
|
5027
|
64 |
fun context thy = set_context (Some thy);
|
|
65 |
fun reset_context () = set_context None;
|
4338
|
66 |
|
|
67 |
|
4843
|
68 |
(* map context *)
|
|
69 |
|
4486
|
70 |
nonfix >>;
|
5027
|
71 |
fun >> f = set_context (Some (f (the_context ())));
|
4486
|
72 |
|
|
73 |
|
4843
|
74 |
(* retrieve thms *)
|
|
75 |
|
5059
|
76 |
fun thm name = PureThy.get_thm (the_context ()) name;
|
|
77 |
fun thms name = PureThy.get_thms (the_context ()) name;
|
4843
|
78 |
|
|
79 |
|
4914
|
80 |
(* shortcut goal commands *)
|
|
81 |
|
5042
|
82 |
fun Goal s = Goals.atomic_goal (the_context ()) s;
|
|
83 |
fun Goalw thms s = Goals.atomic_goalw (the_context ()) thms s;
|
4914
|
84 |
|
|
85 |
|
4338
|
86 |
end;
|
|
87 |
|
4486
|
88 |
|
|
89 |
structure BasicContext: BASIC_CONTEXT = Context;
|
|
90 |
open BasicContext;
|