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