1 (* Title: tacticals for programs
2 Author: Walther Neuper, Aug.2019
3 (c) due to copyright terms
6 imports "$ISABELLE_ISAC/BaseDefinitions/BaseDefinitions"
10 Define specific constants for tacticals, which determine the flow of evaluation in programs.
11 Tacticals are not visible in calculations, which are generated by programs as a side effect.
13 subsection \<open>Consts for tacticals\<close>
15 Chain :: "['a => 'a, 'a => 'a, 'a] => 'a" (infixr "#>" 10)
16 Try :: "['a => 'a, 'a] => 'a"
17 Repeat :: "['a => 'a, 'a] => 'a"
18 Or :: "['a => 'a, 'a => 'a, 'a] => 'a" (infixr "Or" 10)
19 While :: "[bool, 'a => 'a, 'a] => 'a" ("((While (_) Do)//(_))" 9)
20 If :: "[bool, 'a, 'a] => 'a" ("(If (_)/ Then (_)/ Else (_))" 10)
22 subsection \<open>ML code for tacticals\<close>
27 val contained_in: term -> bool
32 structure Tactical(**): TACTICAL(**) =
36 val SOME (Let $ _ $ _) = ParseC.term_opt @{context} "let aaa = 1 in aaa"
37 val SOME (Chain) = ParseC.term_opt @{context} "Chain";
38 val SOME (Try) = ParseC.term_opt @{context} "Try";
39 val SOME (Repeat) = ParseC.term_opt @{context} "Repeat";
40 val SOME (Or $ _ $ _) = ParseC.term_opt @{context} "aaa Or bbb";
41 val SOME (While $ _ $ _) = ParseC.term_opt @{context} "While aaa Do bbb";
42 val SOME (If $ _ $ _ $ _) = ParseC.term_opt @{context} "If aaa Then bbb Else ccc";
44 val all_Consts = [Let, Chain, Try, Repeat, Or, While, If]
46 fun is t = TermC.contains_Const_typeless all_Consts t
50 fun eqal (Const (fid, _), Const (constid, _)) = fid = constid
52 val (f, args) = strip_comb t
54 if member eqal all_Consts f
56 else fold cor_ (map contained_in args) false