src/Pure/section_utils.ML
changeset 4848 99c8d95c51d6
parent 4695 6aa25ee18fc4
child 4938 c8bbbf3c59fa
equal deleted inserted replaced
4847:ea7d7a65e4e9 4848:99c8d95c51d6
     1 (*  Title: 	Pure/section-utils
     1 (*  Title: 	Pure/section_utils.ML
     2     ID:         $Id$
     2     ID:         $Id$
     3     Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
     3     Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1994  University of Cambridge
     4     Copyright   1994  University of Cambridge
     5 
     5 
     6 Utilities for writing new theory sections
     6 Utilities for writing new theory sections.
     7 *)
     7 *)
     8 
     8 
     9 fun ap t u = t$u;
     9 fun ap t u = t$u;
    10 fun app t (u1,u2) = t $ u1 $ u2;
    10 fun app t (u1,u2) = t $ u1 $ u2;
    11 
    11 
    12 (*Make distinct individual variables a1, a2, a3, ..., an. *)
    12 (*Make distinct individual variables a1, a2, a3, ..., an. *)
    13 fun mk_frees a [] = []
    13 fun mk_frees a [] = []
    14   | mk_frees a (T::Ts) = Free(a,T) :: mk_frees (bump_string a) Ts;
    14   | mk_frees a (T::Ts) = Free(a,T) :: mk_frees (bump_string a) Ts;
    15 
    15 
    16 (*Make a definition lhs==rhs*)
       
    17 fun mk_defpair (lhs, rhs) = 
       
    18   let val Const(name, _) = head_of lhs
       
    19   in (Sign.base_name name ^ "_def", Logic.mk_equals (lhs, rhs)) end;
       
    20 
       
    21 fun get_def thy s = get_axiom thy (s^"_def");
       
    22 
       
    23 
    16 
    24 (*Read an assumption in the given theory*)
    17 (*Read an assumption in the given theory*)
    25 fun assume_read thy a = assume (read_cterm (sign_of thy) (a,propT));
    18 fun assume_read thy a = Thm.assume (read_cterm (sign_of thy) (a,propT));
    26 
    19 
    27 (*Read a term from string "b", with expected type T*)
    20 (*Read a term from string "b", with expected type T*)
    28 fun readtm sign T b = 
    21 fun readtm sign T b = 
    29     read_cterm sign (b,T) |> term_of
    22     read_cterm sign (b,T) |> term_of
    30     handle ERROR => error ("The error(s) above occurred for " ^ b);
    23     handle ERROR => error ("The error(s) above occurred for " ^ b);
    63 	   then front @ escape (tl (snd (take_prefix Symbol.is_blank rest)))
    56 	   then front @ escape (tl (snd (take_prefix Symbol.is_blank rest)))
    64 	   else error ("Unrecognized string escape: " ^ implode(b::c::rest)));
    57 	   else error ("Unrecognized string escape: " ^ implode(b::c::rest)));
    65 
    58 
    66 (*Remove the first and last charaters -- presumed to be quotes*)
    59 (*Remove the first and last charaters -- presumed to be quotes*)
    67 val trim = implode o escape o rev o tl o rev o tl o Symbol.explode;
    60 val trim = implode o escape o rev o tl o rev o tl o Symbol.explode;
    68 
       
    69 
       
    70 (*Check for some named theory*)
       
    71 fun require_thy thy name sect =
       
    72   if exists (equal name) (Sign.stamp_names_of (sign_of thy)) then ()
       
    73   else error ("Need theory " ^ quote name ^ " as an ancestor for " ^ sect);