| 
316
 | 
     1  | 
% !TEX program = xelatex
  | 
| 
66
 | 
     2  | 
\documentclass[dvipsnames,14pt,t,xelatex]{beamer}
 | 
| 
151
 | 
     3  | 
\usepackage{chessboard}
 | 
| 
 | 
     4  | 
\usepackage[LSBC4,T1]{fontenc}
 | 
| 
66
 | 
     5  | 
\usepackage{../slides}
 | 
| 
 | 
     6  | 
\usepackage{../graphics}
 | 
| 
 | 
     7  | 
\usepackage{../langs}
 | 
| 
151
 | 
     8  | 
  | 
| 
148
 | 
     9  | 
% \usepackage{../data}
 | 
| 
66
 | 
    10  | 
  | 
| 
 | 
    11  | 
\hfuzz=220pt 
  | 
| 
 | 
    12  | 
  | 
| 
 | 
    13  | 
%\setmonofont[Scale=.88]{Consolas}
 | 
| 
 | 
    14  | 
%\newfontfamily{\consolas}{Consolas}
 | 
| 
 | 
    15  | 
  | 
| 
 | 
    16  | 
\lstset{language=Scala,
 | 
| 
 | 
    17  | 
        style=mystyle,
  | 
| 
 | 
    18  | 
        numbersep=0pt,
  | 
| 
 | 
    19  | 
        numbers=none,
  | 
| 
 | 
    20  | 
        xleftmargin=0mm}
  | 
| 
 | 
    21  | 
  | 
| 
 | 
    22  | 
\newcommand{\bl}[1]{\textcolor{blue}{#1}}     
 | 
| 
 | 
    23  | 
  | 
| 
 | 
    24  | 
% beamer stuff 
  | 
| 
 | 
    25  | 
\renewcommand{\slidecaption}{PEP (Scala) 02, King's College London}
 | 
| 
 | 
    26  | 
  | 
| 
 | 
    27  | 
  | 
| 
 | 
    28  | 
\begin{document}
 | 
| 
 | 
    29  | 
  | 
| 
 | 
    30  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
 | 
    31  | 
\begin{frame}[t]
 | 
| 
 | 
    32  | 
\frametitle{%
 | 
| 
 | 
    33  | 
  \begin{tabular}{@ {}c@ {}}
 | 
| 
 | 
    34  | 
  \\[5mm]
  | 
| 
 | 
    35  | 
  \huge PEP Scala (2) 
  | 
| 
 | 
    36  | 
  \end{tabular}}
 | 
| 
 | 
    37  | 
  | 
| 
 | 
    38  | 
  \normalsize
  | 
| 
 | 
    39  | 
  \begin{center}
 | 
| 
 | 
    40  | 
  \begin{tabular}{ll}
 | 
| 
147
 | 
    41  | 
    Email:  & christian.urban at kcl.ac.uk\\
  | 
| 
316
 | 
    42  | 
    Office: & N\liningnums{7.07} (North Wing, Bush House)\bigskip\\
 | 
| 
 | 
    43  | 
    Slides \& Code: & KEATS\bigskip\\
  | 
| 
 | 
    44  | 
    Office Hours: &  Thursdays 12:00 -- 14:00\\
  | 
| 
 | 
    45  | 
    Additionally: & (for Scala) Tuesdays 10:45 -- 11:45\\ 
  | 
| 
66
 | 
    46  | 
  \end{tabular}
 | 
| 
 | 
    47  | 
  \end{center}
 | 
| 
 | 
    48  | 
  | 
| 
 | 
    49  | 
  | 
| 
 | 
    50  | 
\end{frame}
 | 
| 
 | 
    51  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  | 
| 
 | 
    52  | 
  | 
| 
316
 | 
    53  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  | 
| 
 | 
    54  | 
\begin{frame}[c,fragile]
 | 
| 
 | 
    55  | 
  \frametitle{My Scala Version}
 | 
| 
 | 
    56  | 
  
  | 
| 
 | 
    57  | 
  \begin{lstlisting}[language={},numbers=none,
 | 
| 
 | 
    58  | 
    basicstyle=\ttfamily\small,xleftmargin=-2mm]
  | 
| 
 | 
    59  | 
  $ scala
  | 
| 
 | 
    60  | 
    
  | 
| 
 | 
    61  | 
  Welcome to Scala 2.13.1 (Java HotSpot(TM) 
  | 
| 
 | 
    62  | 
  64-Bit Server VM, Java 9). Type in expressions 
  | 
| 
 | 
    63  | 
  for evaluation. Or try :help.
  | 
| 
 | 
    64  | 
  
  | 
| 
 | 
    65  | 
  scala>
  | 
| 
 | 
    66  | 
  \end{lstlisting}%$
 | 
| 
 | 
    67  | 
  \bigskip\bigskip
  | 
| 
 | 
    68  | 
  
  | 
| 
 | 
    69  | 
  With older versions you will get strange results with my reference implementation.
  | 
| 
 | 
    70  | 
  
  | 
| 
 | 
    71  | 
  \end{frame}
 | 
| 
 | 
    72  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
202
 | 
    73  | 
  | 
| 
147
 | 
    74  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  | 
| 
202
 | 
    75  | 
\begin{frame}[c,fragile]
 | 
| 
316
 | 
    76  | 
\frametitle{Reference Implementation}
 | 
| 
 | 
    77  | 
  
  | 
| 
 | 
    78  | 
Keep your implementation and my reference implementation separate.\bigskip
  | 
| 
147
 | 
    79  | 
  | 
| 
316
 | 
    80  | 
  \begin{lstlisting}[language={},numbers=none,
 | 
| 
 | 
    81  | 
    basicstyle=\ttfamily\small,xleftmargin=-2mm]
  | 
| 
 | 
    82  | 
  $ scala -cp collatz.jar
  | 
| 
202
 | 
    83  | 
  
  | 
| 
316
 | 
    84  | 
  scala> CW6a.collatz(6)
  | 
| 
 | 
    85  | 
  res0: Long = 8
  | 
| 
 | 
    86  | 
  | 
| 
147
 | 
    87  | 
  | 
| 
316
 | 
    88  | 
  scala> import CW6a._
  | 
| 
 | 
    89  | 
  scala> collatz(9)
  | 
| 
 | 
    90  | 
  res1: Long = 19
  | 
| 
 | 
    91  | 
  \end{lstlisting}%$
 | 
| 
202
 | 
    92  | 
  | 
| 
147
 | 
    93  | 
\end{frame}
 | 
| 
 | 
    94  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
316
 | 
    95  | 
  
  | 
| 
 | 
    96  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  | 
| 
 | 
    97  | 
\begin{frame}[t]
 | 
| 
 | 
    98  | 
  \frametitle{Preliminary Part 7}
 | 
| 
 | 
    99  | 
  
  | 
| 
 | 
   100  | 
  \Large
  | 
| 
 | 
   101  | 
  \[
  | 
| 
 | 
   102  | 
    \texttt{overlap}(d_1, d_2) = \frac{d_1 \cdot d_2}{max(d_1^2, d_2^2)}  
 | 
| 
 | 
   103  | 
  \]\bigskip
  | 
| 
 | 
   104  | 
  | 
| 
 | 
   105  | 
  \large
  | 
| 
 | 
   106  | 
  \quad{}\;where \;$d_1^2$\; means \;$d_1 \cdot d_1$\; and so on
 | 
| 
 | 
   107  | 
\end{frame}
 | 
| 
 | 
   108  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
 | 
   109  | 
  
  | 
| 
147
 | 
   110  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  | 
| 
 | 
   111  | 
\begin{frame}[c]
 | 
| 
317
 | 
   112  | 
  \frametitle{Discussion Forum}
 | 
| 
 | 
   113  | 
  
  | 
| 
 | 
   114  | 
  \large
  | 
| 
 | 
   115  | 
  ``Since we cant use \code{var}s I was wondering if we could use a stack?''
 | 
| 
 | 
   116  | 
  \bigskip\bigskip\bigskip\bigskip
  | 
| 
147
 | 
   117  | 
  | 
| 
317
 | 
   118  | 
  \small
  | 
| 
 | 
   119  | 
  My \pcode{collatz} and \pcode{collatz_max} functions are 4 loc each. 
 | 
| 
204
 | 
   120  | 
\end{frame}
 | 
| 
 | 
   121  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
 | 
   122  | 
  | 
| 
 | 
   123  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
 | 
   124  | 
\begin{frame}[t]
 | 
| 
317
 | 
   125  | 
  \frametitle{Email: Hate 'val'}
 | 
| 
 | 
   126  | 
  
  | 
| 
 | 
   127  | 
  \mbox{}\\[-22mm]\mbox{}
 | 
| 
 | 
   128  | 
  
  | 
| 
 | 
   129  | 
  \begin{center}
 | 
| 
 | 
   130  | 
    \begin{bubble}[10.5cm]
 | 
| 
 | 
   131  | 
    Subject: \textbf{Hate '\textbf{\texttt{val}}'}\hfill 01:00 AM\medskip\\
 | 
| 
 | 
   132  | 
  
  | 
| 
 | 
   133  | 
    Hello Mr Urban,\medskip\\
  | 
| 
 | 
   134  | 
  
  | 
| 
 | 
   135  | 
    I just wanted to ask, how are we suppose to work
  | 
| 
 | 
   136  | 
    with the completely useless \textbf{\texttt{val}}, that can’t be changed ever? Why is
 | 
| 
 | 
   137  | 
    this rule active at all? I’ve spent 4 hours not thinking on the
  | 
| 
 | 
   138  | 
    coursework, but how to bypass this annoying rule. What’s the whole
  | 
| 
 | 
   139  | 
    point of all these coursework, when we can’t use everything Scala
  | 
| 
 | 
   140  | 
    gives us?!?\medskip\\
  | 
| 
 | 
   141  | 
  
  | 
| 
 | 
   142  | 
    Regards.\\
  | 
| 
 | 
   143  | 
    \mbox{}\hspace{5mm}\textcolor{black!50}{<<deleted>>}\\
 | 
| 
 | 
   144  | 
    \end{bubble}
 | 
| 
 | 
   145  | 
  \end{center}
 | 
| 
 | 
   146  | 
  
  | 
| 
 | 
   147  | 
\end{frame}
 | 
| 
 | 
   148  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  | 
| 
 | 
   149  | 
  
  | 
| 
 | 
   150  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
 | 
   151  | 
\begin{frame}[c]
 | 
| 
204
 | 
   152  | 
  | 
| 
317
 | 
   153  | 
 \mbox{}\\[-25mm]\mbox{}
 | 
| 
204
 | 
   154  | 
  | 
| 
 | 
   155  | 
\begin{center}
 | 
| 
 | 
   156  | 
  \begin{bubble}[10.5cm]
 | 
| 
317
 | 
   157  | 
  Subject: \textbf{Re: Hate '\textbf{\texttt{val}}'}\hfill 01:02 AM\bigskip\bigskip\\
 | 
| 
204
 | 
   158  | 
  | 
| 
317
 | 
   159  | 
  \textcolor{black!70}{
 | 
| 
 | 
   160  | 
    \textit{\large<<my usual rant about fp\ldots\\ concurrency bla bla\ldots{} better programs
 | 
| 
 | 
   161  | 
    yada>>}}\bigskip\bigskip\bigskip
  | 
| 
 | 
   162  | 
  
  | 
| 
 | 
   163  | 
  PS: What are you trying to do where you desperately want to use \texttt{var}?
 | 
| 
204
 | 
   164  | 
  \end{bubble}
 | 
| 
 | 
   165  | 
\end{center}
 | 
| 
 | 
   166  | 
  | 
| 
 | 
   167  | 
\end{frame}
 | 
| 
 | 
   168  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  | 
| 
 | 
   169  | 
  | 
| 
317
 | 
   170  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
 | 
   171  | 
\begin{frame}[c,fragile]
 | 
| 
 | 
   172  | 
  | 
| 
 | 
   173  | 
\begin{textblock}{6}(0.5,0.5)
 | 
| 
 | 
   174  | 
\begin{bubble}[11.5cm]
 | 
| 
 | 
   175  | 
  \small  
  | 
| 
 | 
   176  | 
  Subject: \textbf{Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:04 AM\medskip\\
 | 
| 
204
 | 
   177  | 
  | 
| 
317
 | 
   178  | 
  \textbf{Right now my is\_legal function works fine:}
 | 
| 
 | 
   179  | 
  
  | 
| 
 | 
   180  | 
\footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
 | 
| 
 | 
   181  | 
 def is_legal(dim: Int, path: Path)(x: Pos): Boolean = {
 | 
| 
 | 
   182  | 
   var boolReturn = false
  | 
| 
 | 
   183  | 
   if(x._1 > dim || x._2 > dim || x._1 < 0 || x._2 < 0) {
 | 
| 
 | 
   184  | 
   else { var breakLoop = false
 | 
| 
 | 
   185  | 
          if(path == Nil) { boolReturn = true }
 | 
| 
 | 
   186  | 
          else { for(i <- 0 until path.length) {
 | 
| 
 | 
   187  | 
                    if(breakLoop == false) {
 | 
| 
 | 
   188  | 
                      if(path(i) == x) {
 | 
| 
 | 
   189  | 
                        boolReturn = true
  | 
| 
 | 
   190  | 
                        breakLoop = true
  | 
| 
 | 
   191  | 
                      }
  | 
| 
 | 
   192  | 
                      else { boolReturn = false }
 | 
| 
 | 
   193  | 
                    } else breakLoop
  | 
| 
 | 
   194  | 
            }
  | 
| 
 | 
   195  | 
          }
  | 
| 
 | 
   196  | 
          boolReturn
  | 
| 
 | 
   197  | 
   }
  | 
| 
 | 
   198  | 
\end{lstlisting}
 | 
| 
 | 
   199  | 
\end{bubble}
 | 
| 
 | 
   200  | 
\end{textblock}
 | 
| 
204
 | 
   201  | 
  | 
| 
317
 | 
   202  | 
\begin{textblock}{6}(8.2,11.8)
 | 
| 
 | 
   203  | 
\begin{bubble}[5.5cm]\footnotesize\bf
 | 
| 
 | 
   204  | 
\ldots{}but I can’t make it work with boolReturn being val. What approach would
 | 
| 
 | 
   205  | 
you recommend in this case, and is using var in this case justified?
  | 
| 
 | 
   206  | 
\end{bubble}
 | 
| 
204
 | 
   207  | 
\end{textblock}
 | 
| 
 | 
   208  | 
  | 
| 
317
 | 
   209  | 
\only<2>{
 | 
| 
 | 
   210  | 
\begin{textblock}{6}(0.3,11.8)
 | 
| 
 | 
   211  | 
  \begin{bubble}[3.1cm]
 | 
| 
 | 
   212  | 
    \textbf{Me:}
 | 
| 
 | 
   213  | 
    \raisebox{-12mm}{\includegraphics[scale=0.08]{../pics/throwup.jpg}}
 | 
| 
 | 
   214  | 
  \end{bubble}
 | 
| 
 | 
   215  | 
\end{textblock}}
 | 
| 
 | 
   216  | 
  | 
| 
 | 
   217  | 
\end{frame}
 | 
| 
 | 
   218  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  | 
| 
 | 
   219  | 
  | 
| 
 | 
   220  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
 | 
   221  | 
\begin{frame}[t,fragile]
 | 
| 
 | 
   222  | 
  | 
| 
 | 
   223  | 
\mbox{}\\[-25mm]\mbox{}
 | 
| 
 | 
   224  | 
  | 
| 
 | 
   225  | 
\begin{textblock}{6}(0.5,2)
 | 
| 
 | 
   226  | 
  \begin{bubble}[11.5cm]
 | 
| 
 | 
   227  | 
  Subject: \textbf{Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:06 AM\bigskip\\
 | 
| 
 | 
   228  | 
  \small
  | 
| 
 | 
   229  | 
  
  | 
| 
 | 
   230  | 
  OK. So you want to make sure that the \texttt{x}-position is not outside the
 | 
| 
 | 
   231  | 
  board....and furthermore you want to make sure that the \texttt{x}-position
 | 
| 
 | 
   232  | 
  is not yet in the path list. How about something like\bigskip
  | 
| 
 | 
   233  | 
  | 
| 
 | 
   234  | 
\footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
 | 
| 
 | 
   235  | 
 def is_legal(dim: Int, path: Path)(x: Pos): Boolean = 
  | 
| 
 | 
   236  | 
   ...<<some board conditions>>... && !path.contains(x)
  | 
| 
 | 
   237  | 
\end{lstlisting}\bigskip
 | 
| 
 | 
   238  | 
  
  | 
| 
 | 
   239  | 
  \small Does not even contain a \texttt{val}.
 | 
| 
 | 
   240  | 
  \end{bubble}
 | 
| 
 | 
   241  | 
\end{textblock}
 | 
| 
 | 
   242  | 
  | 
| 
 | 
   243  | 
\begin{textblock}{6}(7,12)
 | 
| 
 | 
   244  | 
\footnotesize\textcolor{black!50}{(This is all on one line)}
 | 
| 
204
 | 
   245  | 
\end{textblock}
 | 
| 
 | 
   246  | 
  | 
| 
317
 | 
   247  | 
\end{frame}
 | 
| 
 | 
   248  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  | 
| 
 | 
   249  | 
  | 
| 
 | 
   250  | 
  | 
| 
 | 
   251  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
 | 
   252  | 
\begin{frame}[t,fragile]
 | 
| 
 | 
   253  | 
  | 
| 
 | 
   254  | 
\mbox{}\\[-15mm]\mbox{}
 | 
| 
 | 
   255  | 
  | 
| 
 | 
   256  | 
\begin{textblock}{6}(1,3)
 | 
| 
 | 
   257  | 
  \begin{bubble}[10.5cm]
 | 
| 
 | 
   258  | 
    Subject: \textbf{Re: Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 11:02 AM\bigskip\bigskip\\
 | 
| 
 | 
   259  | 
    
  | 
| 
 | 
   260  | 
    THANK YOU! You made me change my coding perspective. Because of you,
  | 
| 
 | 
   261  | 
    I figured out the next one\ldots
  | 
| 
 | 
   262  | 
  \end{bubble}
 | 
| 
 | 
   263  | 
\end{textblock}
 | 
| 
147
 | 
   264  | 
  | 
| 
317
 | 
   265  | 
\only<2>{
 | 
| 
 | 
   266  | 
\begin{textblock}{6}(0.3,11.8)
 | 
| 
 | 
   267  | 
  \begin{bubble}[3.1cm]
 | 
| 
 | 
   268  | 
    \textbf{Me:}
 | 
| 
 | 
   269  | 
    \raisebox{-12mm}{\includegraphics[scale=0.15]{../pics/happy.jpg}}
 | 
| 
 | 
   270  | 
  \end{bubble}
 | 
| 
 | 
   271  | 
\end{textblock}}
 | 
| 
 | 
   272  | 
  | 
| 
 | 
   273  | 
\end{frame}
 | 
| 
 | 
   274  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  | 
| 
 | 
   275  | 
  | 
| 
 | 
   276  | 
  | 
| 
 | 
   277  | 
 
  | 
| 
 | 
   278  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  | 
| 
 | 
   279  | 
\begin{frame}[c]
 | 
| 
 | 
   280  | 
\frametitle{Assignments}
 | 
| 
 | 
   281  | 
  | 
| 
 | 
   282  | 
Don't change any names or types in the templates!\bigskip
  | 
| 
 | 
   283  | 
  | 
| 
 | 
   284  | 
Avoid at all costs:
  | 
| 
 | 
   285  | 
  | 
| 
 | 
   286  | 
\begin{itemize}
 | 
| 
 | 
   287  | 
\item \code{var} 
 | 
| 
 | 
   288  | 
\item \code{return} 
 | 
| 
 | 
   289  | 
\item \texttt{ListBuffer}
 | 
| 
 | 
   290  | 
\item \texttt{mutable}
 | 
| 
 | 
   291  | 
\item \texttt{.par}  
 | 
| 
 | 
   292  | 
\end{itemize}\bigskip\bigskip
 | 
| 
 | 
   293  | 
  | 
| 
 | 
   294  | 
I cannot think of a good reason to use stacks.
  | 
| 
147
 | 
   295  | 
\end{frame}
 | 
| 
 | 
   296  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
 | 
   297  | 
  | 
| 
 | 
   298  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  | 
| 
 | 
   299  | 
\begin{frame}[t]
 | 
| 
 | 
   300  | 
\frametitle{For-Comprehensions Again}
 | 
| 
 | 
   301  | 
  | 
| 
 | 
   302  | 
\begin{center}
 | 
| 
 | 
   303  | 
  \begin{tikzpicture}[scale=1,
 | 
| 
 | 
   304  | 
                      node/.style={
 | 
| 
 | 
   305  | 
                      rectangle,rounded corners=3mm,
  | 
| 
 | 
   306  | 
                      very thick,draw=black!50,
  | 
| 
 | 
   307  | 
                      minimum height=18mm, minimum width=20mm,
  | 
| 
 | 
   308  | 
                      top color=white,bottom color=black!20}]
  | 
| 
 | 
   309  | 
  | 
| 
 | 
   310  | 
  \node (A0) at (0.1,0) {\texttt{\textcolor{purple}{\textbf{for}} (\alert<2->{n} <- List(}};
 | 
| 
 | 
   311  | 
  \node (A1) at (2.3,0) {\texttt{\phantom{,}1,}};
 | 
| 
 | 
   312  | 
  \node (A2) at (3.2,0) {\texttt{\phantom{,}2,}};
 | 
| 
 | 
   313  | 
  \node (A3) at (4.1,0) {\texttt{\phantom{,}3,}};
 | 
| 
 | 
   314  | 
  \node (A4) at (5.0,0) {\texttt{\phantom{,}4,}};
 | 
| 
 | 
   315  | 
  \node (A5) at (5.9,0) {\texttt{\phantom{))}5))}};
 | 
| 
 | 
   316  | 
  \node (A6) at (8,0) {\texttt{\textcolor{purple}{\textbf{yield}} \alert<2->{n\,*\,n}}};
 | 
| 
 | 
   317  | 
  | 
| 
 | 
   318  | 
  \onslide<2->{
 | 
| 
 | 
   319  | 
  \node (B0) at (1.4,-3) {\texttt{List(}};
 | 
| 
 | 
   320  | 
  \node (B1) at (2.3,-3) {\texttt{\phantom{,}1,}};
 | 
| 
 | 
   321  | 
  \node (B2) at (3.6,-3) {\texttt{\phantom{,}4,}};
 | 
| 
 | 
   322  | 
  \node (B3) at (4.9,-3) {\texttt{\phantom{,}9,}};
 | 
| 
 | 
   323  | 
  \node (B4) at (6.2,-3) {\texttt{\phantom{,}16,}};
 | 
| 
 | 
   324  | 
  \node (B5) at (7.5,-3) {\texttt{\phantom{,}25)}};}
 | 
| 
 | 
   325  | 
  | 
| 
 | 
   326  | 
  \onslide<2->{
 | 
| 
 | 
   327  | 
  \draw [->,line width=1mm] (A1.south) -- (B1.north);
  | 
| 
 | 
   328  | 
  \draw [->,line width=1mm] (A2.south) -- (B2.north);
  | 
| 
 | 
   329  | 
  \draw [->,line width=1mm] (A3.south) -- (B3.north);
  | 
| 
 | 
   330  | 
  \draw [->,line width=1mm] (A4.south) -- (B4.north);
  | 
| 
 | 
   331  | 
  \draw [->,line width=1mm] (A5.south) -- (B5.north);}
  | 
| 
 | 
   332  | 
  | 
| 
 | 
   333  | 
  \onslide<2->{
 | 
| 
 | 
   334  | 
  \node (Q1) at (-0.45,-0.1) {};
 | 
| 
 | 
   335  | 
  \node (Q2) at (-0.45,-2.8) {};
 | 
| 
 | 
   336  | 
  \node (Q3) at (-0.45,-2.95) {\alert<2->{\texttt{n\,*\,n:}}};
 | 
| 
 | 
   337  | 
  \draw [->,red,line width=1mm] (Q1.south) -- (Q2.north);}
  | 
| 
 | 
   338  | 
 \end{tikzpicture}
 | 
| 
 | 
   339  | 
\end{center}
 | 
| 
 | 
   340  | 
  | 
| 
 | 
   341  | 
\onslide<3>{This is for when the for-comprehension\\ \textbf{yields / produces} a result.}
 | 
| 
 | 
   342  | 
  | 
| 
 | 
   343  | 
\end{frame}
 | 
| 
 | 
   344  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
 | 
   345  | 
  | 
| 
 | 
   346  | 
  | 
| 
 | 
   347  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  | 
| 
 | 
   348  | 
\begin{frame}[t]
 | 
| 
 | 
   349  | 
\frametitle{For-Comprehensions Again}
 | 
| 
 | 
   350  | 
  | 
| 
 | 
   351  | 
\begin{center}
 | 
| 
 | 
   352  | 
  \begin{tikzpicture}[scale=1,
 | 
| 
 | 
   353  | 
                      node/.style={
 | 
| 
 | 
   354  | 
                      rectangle,rounded corners=3mm,
  | 
| 
 | 
   355  | 
                      very thick,draw=black!50,
  | 
| 
 | 
   356  | 
                      minimum height=18mm, minimum width=20mm,
  | 
| 
 | 
   357  | 
                      top color=white,bottom color=black!20}]
  | 
| 
 | 
   358  | 
  | 
| 
 | 
   359  | 
  \node (A0) at (0,0)
  | 
| 
 | 
   360  | 
    {\texttt{\textcolor{purple}{\textbf{for}} (n <- List(1, 2, 3, 4, 5))
 | 
| 
 | 
   361  | 
             \textcolor{purple}{\textbf{yield}} n\,*\,n}};
 | 
| 
 | 
   362  | 
  | 
| 
 | 
   363  | 
  \node (A1) at (0,-1.5) {\LARGE\textbf{vs}};       
 | 
| 
 | 
   364  | 
         
  | 
| 
 | 
   365  | 
  \node (A2) at (0,-3)
  | 
| 
 | 
   366  | 
    {\texttt{\textcolor{purple}{\textbf{for}} (n <- List(1, 2, 3, 4, 5)) println(n)}};
 | 
| 
 | 
   367  | 
 \end{tikzpicture}
 | 
| 
 | 
   368  | 
\end{center}\bigskip
 | 
| 
 | 
   369  | 
  | 
| 
 | 
   370  | 
  | 
| 
 | 
   371  | 
The second version is in case the for \textbf{does not}
 | 
| 
 | 
   372  | 
produce any result.
  | 
| 
 | 
   373  | 
  | 
| 
 | 
   374  | 
\end{frame}
 | 
| 
 | 
   375  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
 | 
   376  | 
  | 
| 
 | 
   377  | 
  | 
| 
 | 
   378  | 
  | 
| 
 | 
   379  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  | 
| 
66
 | 
   380  | 
\begin{frame}[t]
 | 
| 
317
 | 
   381  | 
\frametitle{Option Type}
 | 
| 
66
 | 
   382  | 
  | 
| 
 | 
   383  | 
  | 
| 
 | 
   384  | 
  
  | 
| 
 | 
   385  | 
\end{frame}
 | 
| 
147
 | 
   386  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
66
 | 
   387  | 
  | 
| 
317
 | 
   388  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  | 
| 
 | 
   389  | 
\begin{frame}[t]
 | 
| 
 | 
   390  | 
\frametitle{Higher-Order Functions}
 | 
| 
 | 
   391  | 
  
  | 
| 
 | 
   392  | 
  
  | 
| 
 | 
   393  | 
    
  | 
| 
 | 
   394  | 
\end{frame}
 | 
| 
 | 
   395  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
 | 
   396  | 
  
  | 
| 
 | 
   397  | 
  | 
| 
148
 | 
   398  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  | 
| 
316
 | 
   399  | 
\begin{frame}[c]
 | 
| 
 | 
   400  | 
\frametitle{\begin{tabular}{c}\\[0cm]\alert{Questions?}\end{tabular}}
 | 
| 
66
 | 
   401  | 
  | 
| 
148
 | 
   402  | 
\begin{center}
 | 
| 
316
 | 
   403  | 
  \begin{tabular}[t]{@{}l@{}l@{}}
 | 
| 
 | 
   404  | 
    \includegraphics[scale=0.1]{../pics/mand4.png} & \hspace{4mm}
 | 
| 
 | 
   405  | 
    \raisebox{0mm}{\includegraphics[scale=0.1]{../pics/mand3.png}}      
 | 
| 
 | 
   406  | 
  \end{tabular}     
 | 
| 
 | 
   407  | 
\end{center}
 | 
| 
 | 
   408  | 
  | 
| 
 | 
   409  | 
\begin{center}
 | 
| 
 | 
   410  | 
  My Office Hours: Thursdays 12 -- 14\\
  | 
| 
 | 
   411  | 
  And specifically for Scala: Tuesdays 10:45 -- 11:45
  | 
| 
148
 | 
   412  | 
\end{center}
 | 
| 
66
 | 
   413  | 
\end{frame}
 | 
| 
 | 
   414  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
  | 
| 
 | 
   415  | 
  | 
| 
 | 
   416  | 
  | 
| 
 | 
   417  | 
\end{document}
 | 
| 
 | 
   418  | 
  | 
| 
 | 
   419  | 
%%% Local Variables:  
  | 
| 
 | 
   420  | 
%%% mode: latex
  | 
| 
 | 
   421  | 
%%% TeX-master: t
  | 
| 
 | 
   422  | 
%%% End: 
  | 
| 
 | 
   423  | 
  |