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