src/Pure/Thy/context.ML
changeset 5027 4b1fd9813003
parent 4925 53900a320a87
child 5031 e2280a1eadb2
equal deleted inserted replaced
5026:9a67a024f4b8 5027:4b1fd9813003
     8 signature BASIC_CONTEXT =
     8 signature BASIC_CONTEXT =
     9 sig
     9 sig
    10   val get_session: unit -> string list
    10   val get_session: unit -> string list
    11   val add_session: string -> unit
    11   val add_session: string -> unit
    12   val reset_session: unit -> unit
    12   val reset_session: unit -> unit
    13   val get_context: unit -> theory
    13   val get_context: unit -> theory option
       
    14   val set_context: theory option -> unit
       
    15   val the_context: unit -> theory
    14   val context: theory -> unit
    16   val context: theory -> unit
    15   val reset_context: unit -> unit
    17   val reset_context: unit -> unit
    16   val thm: xstring -> thm
    18   val thm: xstring -> thm
    17   val thms: xstring -> thm list
    19   val thms: xstring -> thm list
    18   val Goal: string -> thm list
    20   val Goal: string -> thm list
    45 
    47 
    46 
    48 
    47 
    49 
    48 (** theory context **)
    50 (** theory context **)
    49 
    51 
    50 val current_theory = ref (None: theory option);
    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;
    51 
    58 
    52 fun get_context () =
    59 fun the_context () =
    53   (case current_theory of
    60   (case get_context () of
    54     ref (Some thy) => thy
    61     Some thy => thy
    55   | _ => error "Unknown theory context");
    62   | _ => error "Unknown theory context");
    56 
    63 
    57 fun context thy = current_theory := Some thy;
    64 fun context thy = set_context (Some thy);
    58 fun reset_context () = current_theory := None;
    65 fun reset_context () = set_context None;
    59 
    66 
    60 
    67 
    61 (* map context *)
    68 (* map context *)
    62 
    69 
    63 nonfix >>;
    70 nonfix >>;
    64 fun >> f = current_theory := Some (f (get_context ()));
    71 fun >> f = set_context (Some (f (the_context ())));
    65 
    72 
    66 
    73 
    67 (* retrieve thms *)
    74 (* retrieve thms *)
    68 
    75 
    69 fun thm name = PureThy.get_thm (get_context ()) name;
    76 fun thm name = PureThy.get_thm (the_context ()) name;
    70 fun thms name = PureThy.get_thms (get_context ()) name;
    77 fun thms name = PureThy.get_thms (the_context ()) name;
    71 
    78 
    72 
    79 
    73 (* shortcut goal commands *)
    80 (* shortcut goal commands *)
    74 
    81 
    75 fun Goal s = Goals.goal (get_context ()) s;
    82 fun Goal s = Goals.goal (the_context ()) s;
    76 fun Goalw thms s = Goals.goalw (get_context ()) thms s;
    83 fun Goalw thms s = Goals.goalw (the_context ()) thms s;
    77 
    84 
    78 
    85 
    79 end;
    86 end;
    80 
    87 
    81 
    88