| 66 |      1 | \documentclass[dvipsnames,14pt,t,xelatex]{beamer}
 | 
|  |      2 | \usepackage{../slides}
 | 
|  |      3 | \usepackage{../graphics}
 | 
|  |      4 | \usepackage{../langs}
 | 
| 148 |      5 | \usepackage{chessboard}
 | 
|  |      6 | \usepackage[LSBC4,T1]{fontenc}
 | 
|  |      7 | % \usepackage{../data}
 | 
| 66 |      8 | 
 | 
|  |      9 | \hfuzz=220pt 
 | 
|  |     10 | 
 | 
|  |     11 | %\setmonofont[Scale=.88]{Consolas}
 | 
|  |     12 | %\newfontfamily{\consolas}{Consolas}
 | 
|  |     13 | 
 | 
|  |     14 | \lstset{language=Scala,
 | 
|  |     15 |         style=mystyle,
 | 
|  |     16 |         numbersep=0pt,
 | 
|  |     17 |         numbers=none,
 | 
|  |     18 |         xleftmargin=0mm}
 | 
|  |     19 | 
 | 
|  |     20 | \newcommand{\bl}[1]{\textcolor{blue}{#1}}     
 | 
|  |     21 | 
 | 
|  |     22 | % beamer stuff 
 | 
|  |     23 | \renewcommand{\slidecaption}{PEP (Scala) 02, King's College London}
 | 
|  |     24 | 
 | 
|  |     25 | 
 | 
|  |     26 | \begin{document}
 | 
|  |     27 | 
 | 
|  |     28 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |     29 | \begin{frame}[t]
 | 
|  |     30 | \frametitle{%
 | 
|  |     31 |   \begin{tabular}{@ {}c@ {}}
 | 
|  |     32 |   \\[5mm]
 | 
|  |     33 |   \huge PEP Scala (2) 
 | 
|  |     34 |   \end{tabular}}
 | 
|  |     35 | 
 | 
|  |     36 |   \normalsize
 | 
|  |     37 |   \begin{center}
 | 
|  |     38 |   \begin{tabular}{ll}
 | 
| 147 |     39 |     Email:  & christian.urban at kcl.ac.uk\\
 | 
|  |     40 |     Office: & N7.07 (North Wing, Bush House)\\
 | 
|  |     41 |     Slides \& Code: & KEATS\medskip\\
 | 
|  |     42 |     Scala Office & \\
 | 
|  |     43 |     Hours: &  Thursdays 11 -- 13\\
 | 
| 66 |     44 |   \end{tabular}
 | 
|  |     45 |   \end{center}
 | 
|  |     46 | 
 | 
|  |     47 | 
 | 
|  |     48 | \end{frame}
 | 
|  |     49 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
|  |     50 | 
 | 
| 147 |     51 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
|  |     52 | \begin{frame}[t,fragile]
 | 
|  |     53 |   \frametitle{Mea Culpa}
 | 
|  |     54 | \bigskip
 | 
|  |     55 |   
 | 
|  |     56 | \mbox{\hspace{-4mm}}CW6, Part 3 (deadline 21 December)\bigskip\medskip  
 | 
|  |     57 | \small
 | 
|  |     58 | \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-4mm]
 | 
|  |     59 | val blchip_portfolio =
 | 
|  |     60 |  List("GOOG", "AAPL", "MSFT", "IBM", "FB",
 | 
|  |     61 |                           "YHOO", "AMZN", "BIDU")
 | 
|  |     62 | 
 | 
|  |     63 | val rstate_portfolio =
 | 
|  |     64 | List("PLD", "PSA", "AMT", "AIV", "AVB",
 | 
|  |     65 |                           "BXP", "CBG", "CCI", 
 | 
|  |     66 |      "DLR", "EQIX", "EQR", "ESS", "EXR",
 | 
|  |     67 |                           "FRT", "GGP", "HCP") 
 | 
|  |     68 | \end{lstlisting}\bigskip
 | 
|  |     69 |                         
 | 
|  |     70 | \onslide<2>{The results in the CW are calculated with YHOO and CBG deleted.}
 | 
|  |     71 | 
 | 
|  |     72 | \only<2>{
 | 
|  |     73 | \begin{textblock}{6}(8.5,6.6)
 | 
|  |     74 |   \begin{tikzpicture}
 | 
|  |     75 |     \node (B0) at (0,0) {};
 | 
|  |     76 |     \node (B1) at (0,0.5) {};
 | 
|  |     77 |     \node (B2) at (1.2,0) {};
 | 
|  |     78 |     \node (B3) at (1.2,0.5) {};
 | 
|  |     79 |     \draw [red,line width=1mm] (B0) -- (B3);
 | 
|  |     80 |     \draw [red,line width=1mm] (B1) -- (B2);
 | 
|  |     81 |   \end{tikzpicture}
 | 
|  |     82 | \end{textblock}}
 | 
|  |     83 | 
 | 
|  |     84 | \only<2>{
 | 
|  |     85 | \begin{textblock}{6}(10.5,9.9)
 | 
|  |     86 |   \begin{tikzpicture}
 | 
|  |     87 |     \node (B0) at (0,0) {};
 | 
|  |     88 |     \node (B1) at (0,0.5) {};
 | 
|  |     89 |     \node (B2) at (1.2,0) {};
 | 
|  |     90 |     \node (B3) at (1.2,0.5) {};
 | 
|  |     91 |     \draw [red,line width=1mm] (B0) -- (B3);
 | 
|  |     92 |     \draw [red,line width=1mm] (B1) -- (B2);
 | 
|  |     93 |   \end{tikzpicture}
 | 
|  |     94 | \end{textblock}}
 | 
|  |     95 | \end{frame}
 | 
|  |     96 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |     97 | 
 | 
|  |     98 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
|  |     99 | \begin{frame}[c]
 | 
|  |    100 | \frametitle{Mea Culpa 2}
 | 
|  |    101 | 
 | 
|  |    102 | Avoid at all costs, even in comments
 | 
|  |    103 | 
 | 
|  |    104 | \begin{itemize}
 | 
|  |    105 | \item \texttt{var} \only<2>{$\quad\Rightarrow\;$\texttt{Var}}
 | 
|  |    106 | \item \texttt{return} \only<2>{$\quad\Rightarrow\;$\texttt{Return}}
 | 
|  |    107 | \item \texttt{.par}
 | 
|  |    108 | \item \texttt{ListBuffer}
 | 
|  |    109 | \item \texttt{mutable}  
 | 
|  |    110 | \end{itemize}
 | 
|  |    111 | 
 | 
|  |    112 | \end{frame}
 | 
|  |    113 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    114 | 
 | 
|  |    115 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
|  |    116 | \begin{frame}[t]
 | 
|  |    117 | \frametitle{For-Comprehensions Again}
 | 
|  |    118 | 
 | 
|  |    119 | \begin{center}
 | 
|  |    120 |   \begin{tikzpicture}[scale=1,
 | 
|  |    121 |                       node/.style={
 | 
|  |    122 |                       rectangle,rounded corners=3mm,
 | 
|  |    123 |                       very thick,draw=black!50,
 | 
|  |    124 |                       minimum height=18mm, minimum width=20mm,
 | 
|  |    125 |                       top color=white,bottom color=black!20}]
 | 
|  |    126 | 
 | 
|  |    127 |   \node (A0) at (0.1,0) {\texttt{\textcolor{purple}{\textbf{for}} (\alert<2->{n} <- List(}};
 | 
|  |    128 |   \node (A1) at (2.3,0) {\texttt{\phantom{,}1,}};
 | 
|  |    129 |   \node (A2) at (3.2,0) {\texttt{\phantom{,}2,}};
 | 
|  |    130 |   \node (A3) at (4.1,0) {\texttt{\phantom{,}3,}};
 | 
|  |    131 |   \node (A4) at (5.0,0) {\texttt{\phantom{,}4,}};
 | 
|  |    132 |   \node (A5) at (5.9,0) {\texttt{\phantom{))}5))}};
 | 
|  |    133 |   \node (A6) at (8,0) {\texttt{\textcolor{purple}{\textbf{yield}} \alert<2->{n\,*\,n}}};
 | 
|  |    134 | 
 | 
|  |    135 |   \onslide<2->{
 | 
|  |    136 |   \node (B0) at (1.4,-3) {\texttt{List(}};
 | 
|  |    137 |   \node (B1) at (2.3,-3) {\texttt{\phantom{,}1,}};
 | 
|  |    138 |   \node (B2) at (3.6,-3) {\texttt{\phantom{,}4,}};
 | 
|  |    139 |   \node (B3) at (4.9,-3) {\texttt{\phantom{,}9,}};
 | 
|  |    140 |   \node (B4) at (6.2,-3) {\texttt{\phantom{,}16,}};
 | 
|  |    141 |   \node (B5) at (7.5,-3) {\texttt{\phantom{,}25)}};}
 | 
|  |    142 | 
 | 
|  |    143 |   \onslide<2->{
 | 
|  |    144 |   \draw [->,line width=1mm] (A1.south) -- (B1.north);
 | 
|  |    145 |   \draw [->,line width=1mm] (A2.south) -- (B2.north);
 | 
|  |    146 |   \draw [->,line width=1mm] (A3.south) -- (B3.north);
 | 
|  |    147 |   \draw [->,line width=1mm] (A4.south) -- (B4.north);
 | 
|  |    148 |   \draw [->,line width=1mm] (A5.south) -- (B5.north);}
 | 
|  |    149 | 
 | 
|  |    150 |   \onslide<2->{
 | 
|  |    151 |   \node (Q1) at (-0.45,-0.1) {};
 | 
|  |    152 |   \node (Q2) at (-0.45,-2.8) {};
 | 
|  |    153 |   \node (Q3) at (-0.45,-2.95) {\alert<2->{\texttt{n\,*\,n:}}};
 | 
|  |    154 |   \draw [->,red,line width=1mm] (Q1.south) -- (Q2.north);}
 | 
|  |    155 |  \end{tikzpicture}
 | 
|  |    156 | \end{center}
 | 
|  |    157 | 
 | 
|  |    158 | \onslide<3>{This is for when the for-comprehension\\ \textbf{yields / produces} a result.}
 | 
|  |    159 | 
 | 
|  |    160 | \end{frame}
 | 
|  |    161 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    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,0)
 | 
|  |    177 |     {\texttt{\textcolor{purple}{\textbf{for}} (n <- List(1, 2, 3, 4, 5))
 | 
|  |    178 |              \textcolor{purple}{\textbf{yield}} n\,*\,n}};
 | 
|  |    179 | 
 | 
|  |    180 |   \node (A1) at (0,-1.5) {\LARGE\textbf{vs}};       
 | 
|  |    181 |          
 | 
|  |    182 |   \node (A2) at (0,-3)
 | 
|  |    183 |     {\texttt{\textcolor{purple}{\textbf{for}} (n <- List(1, 2, 3, 4, 5)) println(n)}};
 | 
|  |    184 |  \end{tikzpicture}
 | 
|  |    185 | \end{center}\bigskip
 | 
|  |    186 | 
 | 
|  |    187 | 
 | 
|  |    188 | The second version is in case the for \textbf{does not}
 | 
|  |    189 | produce any result.
 | 
|  |    190 | 
 | 
|  |    191 | \end{frame}
 | 
|  |    192 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    193 | 
 | 
|  |    194 | 
 | 
|  |    195 | 
 | 
|  |    196 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
| 66 |    197 | \begin{frame}[t]
 | 
| 148 |    198 | \frametitle{Why Scala? No null!}
 | 
| 66 |    199 | 
 | 
|  |    200 | 
 | 
|  |    201 | \begin{itemize}
 | 
|  |    202 | \item \large {\bf You can avoid \textcolor{blue}{\texttt{null}}}:
 | 
|  |    203 | \end{itemize}
 | 
|  |    204 | 
 | 
|  |    205 | 
 | 
|  |    206 | \begin{textblock}{6}(1,5)
 | 
|  |    207 |   \begin{bubble}[10.5cm]\small
 | 
|  |    208 |       ``I call it my billion-dollar mistake. It was the invention of
 | 
|  |    209 |       the null reference in 1965. At that time, I was designing the
 | 
|  |    210 |       first comprehensive type system for references in an object
 | 
|  |    211 |       oriented language (ALGOL W). My goal was to ensure that all use
 | 
|  |    212 |       of references should be absolutely safe, with checking performed
 | 
|  |    213 |       automatically by the compiler. But I couldn't resist the
 | 
|  |    214 |       temptation to put in a null reference, simply because it was so
 | 
|  |    215 |       easy to implement. This has led to innumerable errors,
 | 
|  |    216 |       vulnerabilities, and system crashes, which have probably caused
 | 
|  |    217 |       a billion dollars of pain and damage in the last forty years.''
 | 
|  |    218 |       \hfill Sir Tony (Hoare)
 | 
|  |    219 | \end{bubble}
 | 
|  |    220 | \end{textblock}
 | 
|  |    221 |   
 | 
| 148 |    222 | \begin{textblock}{5}(12.5,1.9)
 | 
|  |    223 | \includegraphics[scale=0.05]{../pics/hoare.jpg}\\
 | 
| 66 |    224 | \end{textblock}
 | 
|  |    225 |   
 | 
|  |    226 | \end{frame}
 | 
| 147 |    227 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
| 66 |    228 | 
 | 
|  |    229 | 
 | 
| 148 |    230 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    231 | \begin{frame}[c,fragile]
 | 
|  |    232 | \frametitle{\begin{tabular}{c}\\[1cm]\alert{Questions?}\end{tabular}}
 | 
| 66 |    233 | 
 | 
| 148 |    234 | \begin{center}
 | 
|  |    235 | \chessboard[maxfield=g7,
 | 
|  |    236 |             color=blue!50,
 | 
|  |    237 |             linewidth=0.2em,
 | 
|  |    238 |             shortenstart=0.5ex,
 | 
|  |    239 |             shortenend=0.5ex,
 | 
|  |    240 |             markstyle=cross,
 | 
|  |    241 |             markfields={a4, c4, Z3, d3, Z1, d1, a0, c0},
 | 
|  |    242 |             color=red!50,
 | 
|  |    243 |             markfields={f5, e6},
 | 
|  |    244 |             boardfontsize=12pt,labelfontsize=8pt,
 | 
|  |    245 |             setpieces={Ng7, Nb2},showmover=false]
 | 
|  |    246 | \end{center}
 | 
|  |    247 |             
 | 
|  |    248 | \begin{center}
 | 
|  |    249 | My Scala Office Hours: Thursdays 11 -- 13
 | 
|  |    250 | \end{center}
 | 
| 66 |    251 | \end{frame}
 | 
|  |    252 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    253 | \end{document}
 | 
|  |    254 | 
 | 
|  |    255 | 
 | 
|  |    256 | \end{document}
 | 
|  |    257 | 
 | 
|  |    258 | %%% Local Variables:  
 | 
|  |    259 | %%% mode: latex
 | 
|  |    260 | %%% TeX-master: t
 | 
|  |    261 | %%% End: 
 | 
|  |    262 | 
 |