| 66 |      1 | \documentclass[dvipsnames,14pt,t,xelatex]{beamer}
 | 
| 151 |      2 | \usepackage{chessboard}
 | 
|  |      3 | \usepackage[LSBC4,T1]{fontenc}
 | 
| 66 |      4 | \usepackage{../slides}
 | 
|  |      5 | \usepackage{../graphics}
 | 
|  |      6 | \usepackage{../langs}
 | 
| 151 |      7 | 
 | 
| 148 |      8 | % \usepackage{../data}
 | 
| 66 |      9 | 
 | 
|  |     10 | \hfuzz=220pt 
 | 
|  |     11 | 
 | 
|  |     12 | %\setmonofont[Scale=.88]{Consolas}
 | 
|  |     13 | %\newfontfamily{\consolas}{Consolas}
 | 
|  |     14 | 
 | 
|  |     15 | \lstset{language=Scala,
 | 
|  |     16 |         style=mystyle,
 | 
|  |     17 |         numbersep=0pt,
 | 
|  |     18 |         numbers=none,
 | 
|  |     19 |         xleftmargin=0mm}
 | 
|  |     20 | 
 | 
|  |     21 | \newcommand{\bl}[1]{\textcolor{blue}{#1}}     
 | 
|  |     22 | 
 | 
|  |     23 | % beamer stuff 
 | 
|  |     24 | \renewcommand{\slidecaption}{PEP (Scala) 02, King's College London}
 | 
|  |     25 | 
 | 
|  |     26 | 
 | 
|  |     27 | \begin{document}
 | 
|  |     28 | 
 | 
|  |     29 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |     30 | \begin{frame}[t]
 | 
|  |     31 | \frametitle{%
 | 
|  |     32 |   \begin{tabular}{@ {}c@ {}}
 | 
|  |     33 |   \\[5mm]
 | 
|  |     34 |   \huge PEP Scala (2) 
 | 
|  |     35 |   \end{tabular}}
 | 
|  |     36 | 
 | 
|  |     37 |   \normalsize
 | 
|  |     38 |   \begin{center}
 | 
|  |     39 |   \begin{tabular}{ll}
 | 
| 147 |     40 |     Email:  & christian.urban at kcl.ac.uk\\
 | 
| 202 |     41 |     Office: & N\liningnums{7.07} (North Wing, Bush House)\\
 | 
| 147 |     42 |     Slides \& Code: & KEATS\medskip\\
 | 
| 202 |     43 |     Office Hours: &  Mondays 12:00 -- 14:00\\
 | 
| 66 |     44 |   \end{tabular}
 | 
|  |     45 |   \end{center}
 | 
|  |     46 | 
 | 
|  |     47 | 
 | 
|  |     48 | \end{frame}
 | 
|  |     49 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
|  |     50 | 
 | 
| 202 |     51 | 
 | 
| 147 |     52 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
| 202 |     53 | \begin{frame}[c,fragile]
 | 
|  |     54 | \frametitle{Scala on Lab Computers}
 | 
| 147 |     55 | 
 | 
| 202 |     56 | \begin{lstlisting}[language={},numbers=none,
 | 
|  |     57 |   basicstyle=\ttfamily\small,xleftmargin=-2mm]
 | 
|  |     58 | $ /usr/share/scala/bin/scala
 | 
|  |     59 |   
 | 
|  |     60 | Welcome to Scala 2.12.6 (Java HotSpot(TM) 64-Bit
 | 
|  |     61 | Server VM, Java 10.0.1). Type in expressions for
 | 
|  |     62 | evaluation. Or try :help.
 | 
| 147 |     63 | 
 | 
| 202 |     64 | scala>
 | 
|  |     65 | \end{lstlisting}%$
 | 
|  |     66 | 
 | 
| 147 |     67 | \end{frame}
 | 
|  |     68 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |     69 | 
 | 
|  |     70 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
|  |     71 | \begin{frame}[c]
 | 
| 204 |     72 | \frametitle{Assignments}
 | 
| 147 |     73 | 
 | 
| 204 |     74 | Don't change anything with the templates!\bigskip
 | 
|  |     75 | 
 | 
|  |     76 | Avoid at all costs:
 | 
| 147 |     77 | 
 | 
|  |     78 | \begin{itemize}
 | 
| 204 |     79 | \item \texttt{var} 
 | 
|  |     80 | \item \texttt{return} 
 | 
| 147 |     81 | \item \texttt{ListBuffer}
 | 
| 204 |     82 | \item \texttt{mutable}
 | 
|  |     83 | \item \texttt{.par}  
 | 
|  |     84 | \end{itemize}\pause\bigskip
 | 
|  |     85 | 
 | 
|  |     86 | 
 | 
|  |     87 | \mbox{}\hfill\textit{``Scala --- \underline{S}lowly \underline{c}ompiled 
 | 
|  |     88 | \underline{a}cademic \underline{la}nguage''}\smallskip\\
 | 
|  |     89 | \mbox{}\hfill\textit{ --- a joke(?) found on Twitter}\bigskip
 | 
|  |     90 | \end{frame}
 | 
|  |     91 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |     92 | 
 | 
|  |     93 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |     94 | \begin{frame}[t]
 | 
|  |     95 | \frametitle{Email: Hate 'val'}
 | 
|  |     96 | 
 | 
|  |     97 | \mbox{}\\[-25mm]\mbox{}
 | 
|  |     98 | 
 | 
|  |     99 | \begin{center}
 | 
|  |    100 |   \begin{bubble}[10.5cm]
 | 
|  |    101 |   Subject: \textbf{Hate '\textbf{\texttt{val}}'}\hfill 01:00 AM\medskip\\
 | 
|  |    102 | 
 | 
|  |    103 |   Hello Mr Urban,\medskip\\
 | 
|  |    104 | 
 | 
|  |    105 |   I just wanted to ask, how are we suppose to work
 | 
|  |    106 |   with the completely useless \textbf{\texttt{val}}, that can’t be changed ever? Why is
 | 
|  |    107 |   this rule active at all? I’ve spent 4 hours not thinking on the
 | 
|  |    108 |   coursework, but how to bypass this annoying rule. What’s the whole
 | 
|  |    109 |   point of all these coursework, when we can’t use everything Scala
 | 
|  |    110 |   gives us?!?\medskip\\
 | 
|  |    111 | 
 | 
|  |    112 |   Regards.\\
 | 
|  |    113 |   \mbox{}\hspace{5mm}\textcolor{black!50}{<<deleted>>}\\
 | 
|  |    114 |   \end{bubble}
 | 
|  |    115 | \end{center}
 | 
|  |    116 | 
 | 
|  |    117 | \end{frame}
 | 
|  |    118 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
|  |    119 | 
 | 
|  |    120 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    121 | \def\firstcircle{(0,0) circle (1.4cm)}
 | 
|  |    122 | \def\secondcircle{(0:2cm) circle (1.4cm)}
 | 
|  |    123 | \colorlet{circle edge}{blue!50}
 | 
|  |    124 | \colorlet{circle area}{blue!20}
 | 
|  |    125 | 
 | 
|  |    126 | \tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
 | 
|  |    127 |     outline/.style={draw=circle edge, thick}}
 | 
|  |    128 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    129 | \begin{frame}[c,fragile]
 | 
|  |    130 | \frametitle{Par: Intersections}
 | 
|  |    131 | 
 | 
|  |    132 | \begin{textblock}{6}(1,2)
 | 
|  |    133 | \begin{tikzpicture}
 | 
|  |    134 |   \draw[outline] \firstcircle node {$A$};
 | 
|  |    135 |   \node[anchor=south] at (current bounding box.north)
 | 
|  |    136 |     {$A = \{1,2,3,\ldots,1000\}$};
 | 
|  |    137 | \end{tikzpicture}
 | 
|  |    138 | \end{textblock}
 | 
|  |    139 | 
 | 
|  |    140 | \begin{textblock}{6}(8,2)
 | 
|  |    141 | \begin{tikzpicture}
 | 
|  |    142 |   \draw[outline] \secondcircle node {$B$};
 | 
|  |    143 |   \node[anchor=south] at (current bounding box.north)
 | 
|  |    144 |     {$B = \{1,5,9,13,\ldots,997\}$};
 | 
|  |    145 | \end{tikzpicture}
 | 
|  |    146 | \end{textblock}
 | 
|  |    147 | 
 | 
|  |    148 | \begin{textblock}{6}(3.3,9)
 | 
|  |    149 | \begin{tikzpicture}
 | 
|  |    150 |     \begin{scope}
 | 
|  |    151 |         \clip \firstcircle;
 | 
|  |    152 |         \fill[filled] \secondcircle;
 | 
|  |    153 |     \end{scope}
 | 
|  |    154 |     \draw[outline] \firstcircle node {$A$};
 | 
|  |    155 |     \draw[outline] \secondcircle node {$B$};
 | 
|  |    156 |     \node[anchor=north] at (current bounding box.south)
 | 
|  |    157 |     {How many elements are in $A \cap B$?};
 | 
|  |    158 | \end{tikzpicture}
 | 
|  |    159 | \end{textblock}  
 | 
| 147 |    160 | 
 | 
|  |    161 | \end{frame}
 | 
|  |    162 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    163 | 
 | 
|  |    164 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
|  |    165 | \begin{frame}[t]
 | 
|  |    166 | \frametitle{For-Comprehensions Again}
 | 
|  |    167 | 
 | 
|  |    168 | \begin{center}
 | 
|  |    169 |   \begin{tikzpicture}[scale=1,
 | 
|  |    170 |                       node/.style={
 | 
|  |    171 |                       rectangle,rounded corners=3mm,
 | 
|  |    172 |                       very thick,draw=black!50,
 | 
|  |    173 |                       minimum height=18mm, minimum width=20mm,
 | 
|  |    174 |                       top color=white,bottom color=black!20}]
 | 
|  |    175 | 
 | 
|  |    176 |   \node (A0) at (0.1,0) {\texttt{\textcolor{purple}{\textbf{for}} (\alert<2->{n} <- List(}};
 | 
|  |    177 |   \node (A1) at (2.3,0) {\texttt{\phantom{,}1,}};
 | 
|  |    178 |   \node (A2) at (3.2,0) {\texttt{\phantom{,}2,}};
 | 
|  |    179 |   \node (A3) at (4.1,0) {\texttt{\phantom{,}3,}};
 | 
|  |    180 |   \node (A4) at (5.0,0) {\texttt{\phantom{,}4,}};
 | 
|  |    181 |   \node (A5) at (5.9,0) {\texttt{\phantom{))}5))}};
 | 
|  |    182 |   \node (A6) at (8,0) {\texttt{\textcolor{purple}{\textbf{yield}} \alert<2->{n\,*\,n}}};
 | 
|  |    183 | 
 | 
|  |    184 |   \onslide<2->{
 | 
|  |    185 |   \node (B0) at (1.4,-3) {\texttt{List(}};
 | 
|  |    186 |   \node (B1) at (2.3,-3) {\texttt{\phantom{,}1,}};
 | 
|  |    187 |   \node (B2) at (3.6,-3) {\texttt{\phantom{,}4,}};
 | 
|  |    188 |   \node (B3) at (4.9,-3) {\texttt{\phantom{,}9,}};
 | 
|  |    189 |   \node (B4) at (6.2,-3) {\texttt{\phantom{,}16,}};
 | 
|  |    190 |   \node (B5) at (7.5,-3) {\texttt{\phantom{,}25)}};}
 | 
|  |    191 | 
 | 
|  |    192 |   \onslide<2->{
 | 
|  |    193 |   \draw [->,line width=1mm] (A1.south) -- (B1.north);
 | 
|  |    194 |   \draw [->,line width=1mm] (A2.south) -- (B2.north);
 | 
|  |    195 |   \draw [->,line width=1mm] (A3.south) -- (B3.north);
 | 
|  |    196 |   \draw [->,line width=1mm] (A4.south) -- (B4.north);
 | 
|  |    197 |   \draw [->,line width=1mm] (A5.south) -- (B5.north);}
 | 
|  |    198 | 
 | 
|  |    199 |   \onslide<2->{
 | 
|  |    200 |   \node (Q1) at (-0.45,-0.1) {};
 | 
|  |    201 |   \node (Q2) at (-0.45,-2.8) {};
 | 
|  |    202 |   \node (Q3) at (-0.45,-2.95) {\alert<2->{\texttt{n\,*\,n:}}};
 | 
|  |    203 |   \draw [->,red,line width=1mm] (Q1.south) -- (Q2.north);}
 | 
|  |    204 |  \end{tikzpicture}
 | 
|  |    205 | \end{center}
 | 
|  |    206 | 
 | 
|  |    207 | \onslide<3>{This is for when the for-comprehension\\ \textbf{yields / produces} a result.}
 | 
|  |    208 | 
 | 
|  |    209 | \end{frame}
 | 
|  |    210 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    211 | 
 | 
|  |    212 | 
 | 
|  |    213 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
|  |    214 | \begin{frame}[t]
 | 
|  |    215 | \frametitle{For-Comprehensions Again}
 | 
|  |    216 | 
 | 
|  |    217 | \begin{center}
 | 
|  |    218 |   \begin{tikzpicture}[scale=1,
 | 
|  |    219 |                       node/.style={
 | 
|  |    220 |                       rectangle,rounded corners=3mm,
 | 
|  |    221 |                       very thick,draw=black!50,
 | 
|  |    222 |                       minimum height=18mm, minimum width=20mm,
 | 
|  |    223 |                       top color=white,bottom color=black!20}]
 | 
|  |    224 | 
 | 
|  |    225 |   \node (A0) at (0,0)
 | 
|  |    226 |     {\texttt{\textcolor{purple}{\textbf{for}} (n <- List(1, 2, 3, 4, 5))
 | 
|  |    227 |              \textcolor{purple}{\textbf{yield}} n\,*\,n}};
 | 
|  |    228 | 
 | 
|  |    229 |   \node (A1) at (0,-1.5) {\LARGE\textbf{vs}};       
 | 
|  |    230 |          
 | 
|  |    231 |   \node (A2) at (0,-3)
 | 
|  |    232 |     {\texttt{\textcolor{purple}{\textbf{for}} (n <- List(1, 2, 3, 4, 5)) println(n)}};
 | 
|  |    233 |  \end{tikzpicture}
 | 
|  |    234 | \end{center}\bigskip
 | 
|  |    235 | 
 | 
|  |    236 | 
 | 
|  |    237 | The second version is in case the for \textbf{does not}
 | 
|  |    238 | produce any result.
 | 
|  |    239 | 
 | 
|  |    240 | \end{frame}
 | 
|  |    241 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    242 | 
 | 
|  |    243 | 
 | 
|  |    244 | 
 | 
|  |    245 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
| 66 |    246 | \begin{frame}[t]
 | 
| 148 |    247 | \frametitle{Why Scala? No null!}
 | 
| 66 |    248 | 
 | 
|  |    249 | 
 | 
|  |    250 | \begin{itemize}
 | 
|  |    251 | \item \large {\bf You can avoid \textcolor{blue}{\texttt{null}}}:
 | 
|  |    252 | \end{itemize}
 | 
|  |    253 | 
 | 
|  |    254 | 
 | 
|  |    255 | \begin{textblock}{6}(1,5)
 | 
|  |    256 |   \begin{bubble}[10.5cm]\small
 | 
|  |    257 |       ``I call it my billion-dollar mistake. It was the invention of
 | 
|  |    258 |       the null reference in 1965. At that time, I was designing the
 | 
|  |    259 |       first comprehensive type system for references in an object
 | 
|  |    260 |       oriented language (ALGOL W). My goal was to ensure that all use
 | 
|  |    261 |       of references should be absolutely safe, with checking performed
 | 
|  |    262 |       automatically by the compiler. But I couldn't resist the
 | 
|  |    263 |       temptation to put in a null reference, simply because it was so
 | 
|  |    264 |       easy to implement. This has led to innumerable errors,
 | 
|  |    265 |       vulnerabilities, and system crashes, which have probably caused
 | 
|  |    266 |       a billion dollars of pain and damage in the last forty years.''
 | 
|  |    267 |       \hfill Sir Tony (Hoare)
 | 
|  |    268 | \end{bubble}
 | 
|  |    269 | \end{textblock}
 | 
|  |    270 |   
 | 
| 148 |    271 | \begin{textblock}{5}(12.5,1.9)
 | 
|  |    272 | \includegraphics[scale=0.05]{../pics/hoare.jpg}\\
 | 
| 66 |    273 | \end{textblock}
 | 
|  |    274 |   
 | 
|  |    275 | \end{frame}
 | 
| 147 |    276 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
| 66 |    277 | 
 | 
|  |    278 | 
 | 
| 148 |    279 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    280 | \begin{frame}[c,fragile]
 | 
|  |    281 | \frametitle{\begin{tabular}{c}\\[1cm]\alert{Questions?}\end{tabular}}
 | 
| 66 |    282 | 
 | 
| 148 |    283 | \begin{center}
 | 
|  |    284 | \chessboard[maxfield=g7,
 | 
|  |    285 |             color=blue!50,
 | 
|  |    286 |             linewidth=0.2em,
 | 
|  |    287 |             shortenstart=0.5ex,
 | 
|  |    288 |             shortenend=0.5ex,
 | 
|  |    289 |             markstyle=cross,
 | 
|  |    290 |             markfields={a4, c4, Z3, d3, Z1, d1, a0, c0},
 | 
|  |    291 |             color=red!50,
 | 
|  |    292 |             markfields={f5, e6},
 | 
|  |    293 |             boardfontsize=12pt,labelfontsize=8pt,
 | 
|  |    294 |             setpieces={Ng7, Nb2},showmover=false]
 | 
|  |    295 | \end{center}
 | 
|  |    296 |             
 | 
|  |    297 | \begin{center}
 | 
| 204 |    298 | My Office Hours: Mondays 12 -- 14
 | 
| 148 |    299 | \end{center}
 | 
| 66 |    300 | \end{frame}
 | 
|  |    301 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    302 | \end{document}
 | 
|  |    303 | 
 | 
|  |    304 | 
 | 
|  |    305 | \end{document}
 | 
|  |    306 | 
 | 
|  |    307 | %%% Local Variables:  
 | 
|  |    308 | %%% mode: latex
 | 
|  |    309 | %%% TeX-master: t
 | 
|  |    310 | %%% End: 
 | 
|  |    311 | 
 |