\usepackage{xcolor}
\usepackage{listings}
\usepackage{clean}
+\usepackage{spl}
\title[cc1516]{SPLC}
\subtitle{\texttt{<splc>~::= <spl> <parser> `,' <lexer> `and' <compiler>}}
\begin{document}
\frame{\titlepage}
+
+\begin{frame}[fragile]
+ \frametitle{Higher order functions implemented using function pointers}
+
+ \begin{SPLCode}
+map(f, xs) :: (a -> b) -> [a] -> [b] {
+ if( isEmpty(xs) ) { return []; }
+ else { return f(xs.hd) : map(f, xs.tl); }
+}
+id(x) { return x; }
+
+main() {
+ map(id, 1:2:3:[]);
+}
+ \end{SPLCode}
+ \pause
+ \begin{itemize}
+ \item Function arguments are passed by name.
+ \item During compilation these are replaced by unique function ID's
+ \item During runtime the corresponding function label is retrieved using
+ a dictionary like approach.
+ \end{itemize}
+
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Functions application can be curried}
+
+ \begin{SPLCode}
+plus(x,y) :: Int -> Int -> Int {
+ return x + y;
+}
+
+main() {
+ map(plus(1), 1:2:3:[]);
+}
+ \end{SPLCode}
+ \pause
+ \begin{columns}[T]
+ \begin{column}[T]{0.5\textwidth}
+ \begin{enumerate}
+ \item Function ID is placed on the heap
+ \item Number of passed arguments is placed on the heap
+ \item Arguments are pushed on the heap
+ \end{enumerate}
+ \end{column}
+ \pause
+ \begin{column}[T]{0.5\textwidth}
+ \begin{block}{Heap contents}
+ \begin{tabular}{c | l | r}
+ address & Content & \\ \hline
+ n & 8 & (1)\\
+ n+1 & 1 & (2)\\
+ n+2 & 4 & (3)
+ \end{tabular}
+ \end{block}
+ \end{column}
+ \end{columns}
+
+\end{frame}
+
\end{document}
--- /dev/null
+\usepackage{listings}
+
+\lstdefinelanguage{SPLCode}{%
+ alsoletter={ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_1234567890},
+ morekeywords={print,isEmpty,if,else,while,read},
+ sensitive=true,
+ morecomment=[l]{//},
+ morecomment=[n]{/*}{*/},
+ morestring=[b]",
+ morestring=[b]',
+ basicstyle=\small,
+ identifierstyle=\small\ttfamily,
+ commentstyle=\itshape,
+ keywordstyle=\bfseries,
+ stringstyle=\ttfamily,
+ showstringspaces=false,
+ basewidth=0.45em,
+ columns=[c]fixed,
+ keepspaces=true,
+ breaklines=true,
+ tabsize=4,
+ texcl=true,
+}
+
+\newcommand{\SPLInline}[1]{\lstinline[language=SPLCode]¦#1¦}
+\newcommand{\SI}[1]{\SPLInline{#1}}
+
+\lstdefinestyle{numbers}{numbers=left, stepnumber=1, numberstyle=\tiny, numbersep=5pt}
+
+\lstnewenvironment{SPLCode}{\lstset{language=SPLCode}}{}