X-Git-Url: http://git.hcoop.net/bpt/mlt.git/blobdiff_plain/c0a3b4882df1afe4a0155654c1102bd0f9729993..HEAD:/doc/manual.tex

diff --git a/doc/manual.tex b/doc/manual.tex
index b86c295..7bd6bb2 100644
--- a/doc/manual.tex
+++ b/doc/manual.tex
@@ -48,6 +48,12 @@ Files consist of a sequence of the following kinds of lines in any order:
 	\item {\tt cm {\it file}}: {\it file} is the path to a file that the SML/NJ Compilation Manager understands (i.e., {\tt .cm}, {\tt .sml}, {\tt .sig}, {\tt .grm}, {\tt .lex}). This file is to be made available to templates in the project.
 
 	\item {\tt print {\it type} = {\it code}}: This declares that the given {\it code} is an SML expression that evaluates to an appropriate function for printing values of the SML {\it type}. The {\it code} should usually be the name of a function defined in a library or project SML source file.
+
+	\item {\tt before {\it template}}: Run {\it template} before every normally-requested template, including its output at the beginning of the final output. This can be used to set up project-wide global state. Performing initialization inside project SML files will not generally be good enough. This is because all of the structure definitions these contain are evaluated at ``compile time,'' causing their code not found inside function definitions to be run only once.
+
+	\item {\tt after {\it template}}: Run {\it template} after every successfully executing template, including its output at the end.
+
+	\item {\tt exn {\it template}}: Run {\it template} when an exception goes uncaught during normal template execution. The function {\tt Web.getExn : unit -> exn} can be used to retrieve the causing exception from within {\it template}. The {\tt before} and {\tt after} templates are not run in the {\tt exn} template when it is executed because of an uncaught exception.
 \end{itemize}
 
 \section{The template language}
@@ -84,7 +90,7 @@ In addition to SML's $\sim$ prefix negation operator, there is a \$ operator for
 
 Function application is like SML application.
 
-\subsection{Tuples}
+\subsubsection{Tuples}
 
 Tuple and {\tt ()} expressions are handled identically to how they are in SML.
 
@@ -96,6 +102,26 @@ The syntax for creating records and extracting their fields is identical to SML'
 
 Where {\tt temp} is the name of a template in the current project, {\tt @temp} evaluates to a function {\tt (string * string) list -> unit} that takes in a list of name-value pairs for CGI parameters to modify and runs {\tt temp} with those changes. The Compilation Manager will prevent template calls from being used to implement any sort of recursion.
 
+\subsubsection{Anonymous functions}
+
+Anonymous {\tt fn} functions are available with the SML syntax.
+
+\subsubsection{\tt case}
+
+SML {\tt case} expressions are supported.
+
+\subsubsection{\tt iff}
+
+SML {\tt if} expressions are supported, except that the keyword that introduces them is {\tt iff}, to disambiguate from {\tt if} statements.
+
+\subsubsection{\tt raise}
+
+SML {\tt raise} expressions are supported.
+
+\subsubsection{\tt let}
+
+SML {\tt let} expressions are supported.
+
 \subsection{Patterns}
 
 Patterns are identical to SML patterns without support for user-defined infix constructors, though {\tt ::} is supported. Record patterns can include field names with no assigned patterns (the pattern for such a field is taken to be the field name) and "flex record" {\tt ...}'s to stand for unused fields.
@@ -123,31 +149,25 @@ Variables with reference type are introduced with {\tt ref} declarations, which
 If statements are in the usual imperative style, meaning that else clauses are optional. They are of the form:
 
 \begin{verbatim}
-if (condition1)
-{
+if condition1 then
 	block1
-}
-else if (condition 2)
-{
-	block 2
-}
+elseif condition 2 then
+	block2
 else
-{
-	block 3
-}
+	block3
+end
 \end{verbatim}
 
-The {\tt block}s are sequences of statements and declarations. Every {\tt if} statement is followed by zero or more {\tt else if}'s and one or zero {\tt else}'s. Conditions must be enclosed in parentheses.
+The {\tt block}s are sequences of statements and declarations. Every {\tt if} statement is followed by zero or more {\tt else if}'s and one or zero {\tt else}'s.
 
 \subsubsection{\tt foreach}
 
 All looping is done via {\tt foreach} statements, which have two forms. One is:
 
 \begin{verbatim}
-foreach (var in exp)
-{
+foreach var in exp do
 	block
-}
+end
 \end{verbatim}
 
 Where {\tt exp} has type {\tt t list}, {\tt block} is executed for each of {\tt exp}'s elements, binding {\tt var} to each of them in order from first to last.
@@ -155,43 +175,34 @@ Where {\tt exp} has type {\tt t list}, {\tt block} is executed for each of {\tt
 There is also a shortcut integer iteration form:
 
 \begin{verbatim}
-foreach (var in fromExp .. toExp)
-{
+for var in fromExp .. toExp do
 	block
-}
+end
 \end{verbatim}
 
 {\tt fromExp} and {\tt toExp} must have type {\tt int}. {\tt block} is evaluated with {\tt var} bound in sequence to each integer in the range defined by {\tt fromExp} and {\tt toExp}.
 
-\subsubsection{\tt case}
+\subsubsection{\tt switch}
 
-{\tt case} statements are straightforward imperative modifications of SML {\tt case} expressions, such as:
+{\tt switch} statements are imperative equivalents of {\tt case} expressions, such as:
 
 \begin{verbatim}
-case (exp)
-(pat1) { block1 }
-(pat2) { block2 }
+switch exp of
+  pat1 => block1
+| pat2 => block2
+end
 \end{verbatim}
 
-The case object and patterns must be enclosed in parentheses.
-
-\subsubsection{{\tt try}..{\tt catch}}
+\subsubsection{{\tt try}..{\tt with}}
 
-This construction is to SML's {\tt handle} what template {\tt case} is to SML {\tt case}. For example:
+This construction is to SML's {\tt handle} what {\tt switch} is to {\tt case}. For example:
 
 \begin{verbatim}
 try
-{
 	block1
-}
-catch (pat1)
-{
-	block2
-}
-catch (pat2)
-{
-	block3
-}
+with pat1 => block2
+| pat2 => block3
+end
 \end{verbatim}
 
 \end{document}
\ No newline at end of file
