some polishing
authorChristian Urban <urbanc@in.tum.de>
Fri, 13 Mar 2009 12:21:44 +0100
changeset 175 7c09bd3227c5
parent 174 a29b81d4fa88
child 176 3da5f3f07d8b
some polishing
CookBook/Recipes/Antiquotes.thy
CookBook/Recipes/TimeLimit.thy
CookBook/Recipes/Timing.thy
CookBook/Solutions.thy
cookbook.pdf
--- a/CookBook/Recipes/Antiquotes.thy	Fri Mar 13 01:15:55 2009 +0100
+++ b/CookBook/Recipes/Antiquotes.thy	Fri Mar 13 12:21:44 2009 +0100
@@ -20,10 +20,10 @@
 
   @{ML [display,gray] "ThyOutput.print_antiquotations ()"}
 
-  Below we give the code for two additional antiquotations that can be used to typeset
-  ML-code and also to check whether the given code actually compiles. This
-  provides a sanity check for the code and also allows one to keep documents
-  in sync with other code, for example Isabelle.
+  Below we give the code for two additional document antiquotations that can
+  be used to typeset ML-code and also to check whether the given code actually
+  compiles. This provides a sanity check for the code and also allows one to
+  keep documents in sync with other code, for example Isabelle.
 
   We first describe the antiquotation @{text "ML_checked"} with the syntax:
  
@@ -32,7 +32,7 @@
   The code is checked by sending the ML-expression @{text [quotes] "val _ =
   a_piece_of_code"} to the ML-compiler (i.e.~the function @{ML
   "ML_Context.eval_in"} in Line 4 below). The complete code of the
-  antiquotation is as follows:
+  document antiquotation is as follows:
 
 *}
 
@@ -45,23 +45,22 @@
 val _ = ThyOutput.antiquotation "ML_checked" (Scan.lift Args.name) output_ml*}
 
 text {*
+  The parser @{ML "(Scan.lift Args.name)"} in line 9 parses a string, in this
+  case the code. As mentioned before, the code is sent to the ML-compiler in
+  the line 4 using the function @{ML ml_val}, which constructs the appropriate
+  ML-expression.  If the code is ``approved'' by the compiler, then the output
+  function @{ML "ThyOutput.output"} in the next line pretty prints the
+  code. This function expects that the code is a list of (pretty)strings where
+  each string correspond to a line in the output. Therefore the use of @{ML
+  "(space_explode \"\\n\" txt)" for txt} which produces this list according to
+  linebreaks.  There are a number of options for antiquotations that are
+  observed by @{ML ThyOutput.output} when printing the code (including @{text
+  "[display]"} and @{text "[quotes]"}). Line 7 sets up the new document
+  antiquotation.
 
-  The parser @{ML "(Scan.lift Args.name)"} in line 9 parses a string, 
-  in this case the code. As mentioned before, the code
-  is sent to the ML-compiler in the line 4 using the function @{ML ml_val},
-  which constructs the appropriate ML-expression.
-  If the code is ``approved'' by the compiler, then the output function @{ML
-  "ThyOutput.output"} in the next line pretty prints the
-  code. This function expects that the code is a list of (pretty)strings where each
-  string correspond to a line in the output. Therefore the use of 
-  @{ML "(space_explode \"\\n\" txt)" for txt} 
-  which produces this list according to linebreaks.  There are a number of options 
-  for antiquotations that are observed by @{ML ThyOutput.output} when printing the 
-  code (including @{text "[display]"} and @{text "[quotes]"}). Line 7 sets 
-  up the new antiquotation.
 
   \begin{readmore}
-  For more information about options of antiquotations see \rsccite{sec:antiq}).
+  For more information about options of document antiquotations see \rsccite{sec:antiq}).
   \end{readmore}
 
   Since we used the argument @{ML "Position.none"}, the compiler cannot give specific 
@@ -86,24 +85,25 @@
   somebody changes the definition of \mbox{@{ML "(op +)"}}.
 
 
-  The second antiquotation we describe extends the first by a pattern that 
-  specifies what the result of the ML-code should be and check 
-  the consistency of the actual result with the given pattern. For this we are going 
-  to implement the antiquotation  
+  The second document antiquotation we describe extends the first by a pattern
+  that specifies what the result of the ML-code should be and check the
+  consistency of the actual result with the given pattern. For this we are
+  going to implement the document antiquotation
+
   
   @{text [display] "@{ML_resp \"a_piece_of_code\" \"a_pattern\"}"}
   
   To add some convenience and also to deal with large outputs, the user can
   give a partial specification inside the pattern by giving abbreviations of
-  the form @{text [quotes] "\<dots>"}. For example @{text "(\<dots>, \<dots>)"} to specify a
+  the form @{text [quotes] "\<dots>"}. For example @{text "(\<dots>, \<dots>)"} for specifying a
   pair.
 
-  Whereas in the antiquotation @{text "@{ML_checked \"piece_of_code\"}"}
-  above, we have sent the expression @{text [quotes] "val _ = piece_of_code"}
-  to the compiler, in the second the wildcard @{text "_"} we will be replaced
-  by the given pattern. To do this we need to replace the @{text [quotes] "\<dots>"}
-  by @{text [quotes] "_"} before sending the code to the compiler. The
-  following function will do this:
+  In the document antiquotation @{text "@{ML_checked \"piece_of_code\"}"}
+  above we have sent the expression @{text [quotes] "val _ = piece_of_code"}
+  to the compiler, now instead the wildcard @{text "_"} we will be replaced by
+  the given pattern. To do this we need to replace in the input the @{text
+  [quotes] "\<dots>"} by @{text [quotes] "_"} before sending the code to the
+  compiler. The following function will do this:
 *}
 
 ML{*fun ml_pat (code_txt, pat) =
@@ -118,19 +118,19 @@
 *}
 
 
-ML{*fun add_resp_indicator pat =
-  map (fn s => "> " ^ s) (space_explode "\n" pat) *}
+ML{*fun add_resp pat = map (fn s => "> " ^ s) pat*}
 
 text {* 
-  The rest of the code of the antiquotation is
+  The rest of the code of the document antiquotation is
 *}
 
 ML{*fun output_ml_resp {context = ctxt, ...} ((code_txt, pat), pos) = 
   (ML_Context.eval_in (SOME ctxt) false pos (ml_pat (code_txt, pat));
    let 
-     val output = (space_explode "\n" code_txt) @ (add_resp_indicator pat)
+     val output1 = space_explode "\n" code_txt 
+     val output2 = add_resp (space_explode "\n" pat)
    in 
-     ThyOutput.output (map Pretty.str output) 
+     ThyOutput.output (map Pretty.str (output1 @ output2)) 
    end)
 
 val _ = ThyOutput.antiquotation "ML_resp" 
@@ -138,7 +138,7 @@
            output_ml_resp*}
 
 text {*
-  This extended antiquotation allows us to write
+  This extended document antiquotation allows us to write
  
   @{text [display] "@{ML_resp [display] \"true andalso false\" \"false\"}"}
 
@@ -155,8 +155,9 @@
   @{ML_resp [display] "let val i = 3 in (i * i, \"foo\") end" "(9, \<dots>)"} 
 
   In both cases, the check by the compiler ensures that code and result
-  match. A limitation of this antiquotation, however, is that the pattern can
-  only be given for values that can be constructed. This excludes
-  values that are abstract datatypes, like theorems or cterms.
+  match. A limitation of this document antiquotation, however, is that the
+  pattern can only be given for values that can be constructed. This excludes
+  values that are abstract datatypes, like @{ML_type thm}s and @{ML_type cterm}s.
+
 *}
 end
\ No newline at end of file
--- a/CookBook/Recipes/TimeLimit.thy	Fri Mar 13 01:15:55 2009 +0100
+++ b/CookBook/Recipes/TimeLimit.thy	Fri Mar 13 12:21:44 2009 +0100
@@ -36,7 +36,7 @@
   is reached.
 
   Note that @{ML  "timeLimit" in TimeLimit} is only meaningful when you use PolyML, 
-  because PolyML has the infrastructure for multithreading programming on 
+  because PolyML has the infrastructure for multithreaded programming on 
   which @{ML "timeLimit" in TimeLimit} relies.
 
 \begin{readmore}
--- a/CookBook/Recipes/Timing.thy	Fri Mar 13 01:15:55 2009 +0100
+++ b/CookBook/Recipes/Timing.thy	Fri Mar 13 12:21:44 2009 +0100
@@ -23,7 +23,8 @@
 
 text {* 
   You can measure how long the simplifier takes to verify a datapoint
-  of this function. The timing can be done using the following wrapper function:
+  of this function. The timing of a tactic can be done using the following 
+  wrapper function:
 *}
 
 ML{*fun timing_wrapper tac st =
@@ -36,12 +37,13 @@
 end*}
 
 text {*
-  Note that this function, in addition to a tactic for which it measures the
-  time, also takes a state @{text "st"} as argument and applies this state to
-  the tactic. The reason is that tactics are lazy functions and you need to force
-  them to run, otherwise the timing will be meaningless.  The time between start
-  and finish of the tactic will be calculated as the end time minus the start time.  
-  An example for the wrapper is the proof
+  Note that this function, in addition to a tactic, also takes a state @{text
+  "st"} as argument and applies this state to the tactic. The reason is that
+  tactics are lazy functions and you need to force them to run, otherwise the
+  timing will be meaningless.  The time between start and finish of the tactic
+  will be calculated as the end time minus the start time.  An example of the
+  wrapper is the proof
+
 
 *}
 
--- a/CookBook/Solutions.thy	Fri Mar 13 01:15:55 2009 +0100
+++ b/CookBook/Solutions.thy	Fri Mar 13 12:21:44 2009 +0100
@@ -128,13 +128,13 @@
   end)*}
 
 text {*
-  A test case is as follows
+  A test case for this conversion is as follows
 *}
 
 lemma "P (Suc (99 + 1)) ((0 + 0)::nat) (Suc (3 + 3 + 3)) (4 + 1)"
   apply(tactic {* add_tac 1 *})?
 txt {* 
-  where the conversion produces the goal state
+  where it produces the goal state
   
   \begin{minipage}{\textwidth}
   @{subgoals [display]}
@@ -202,7 +202,7 @@
 end*}
 
 text {*
-  This is all we need to let the conversion run against the simproc.
+  This is all we need to let the conversion run against the simproc:
 *}
 
 ML{*val _ = Goal.prove @{context} [] [] (goal 8) (K c_tac)
Binary file cookbook.pdf has changed