Working on slides for p4
[cc1516.git] / deliverables / p4 / p4.tex
index 382f8ee..adc62d2 100644 (file)
@@ -3,6 +3,7 @@
 \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}