\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}
Function application is like SML application.
-\subsection{Tuples}
+\subsubsection{Tuples}
Tuple and {\tt ()} expressions are handled identically to how they are in SML.
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.
\begin{verbatim}
if condition1 then
block1
-else if condition 2 then
- block 2
+elseif condition 2 then
+ block2
else
- block 3
+ block3
end
\end{verbatim}
There is also a shortcut integer iteration form:
\begin{verbatim}
-foreach var in fromExp .. toExp do
+for var in fromExp .. toExp do
block
end
\end{verbatim}