22
|
1 |
\documentclass[dvipsnames,14pt,t,xelatex]{beamer}
|
|
2 |
\usepackage{../slides}
|
32
|
3 |
\usepackage{../graphics}
|
22
|
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) 01, 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 (1)
|
|
32 |
\end{tabular}}
|
|
33 |
|
|
34 |
\normalsize
|
|
35 |
\begin{center}
|
|
36 |
\begin{tabular}{ll}
|
137
|
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\\
|
22
|
42 |
\end{tabular}
|
|
43 |
\end{center}
|
|
44 |
|
|
45 |
|
|
46 |
\end{frame}
|
|
47 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
48 |
|
|
49 |
|
|
50 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
51 |
\begin{frame}[c]
|
|
52 |
\frametitle{Why Scala?}
|
|
53 |
|
23
|
54 |
\begin{textblock}{6}(3,4)
|
22
|
55 |
\begin{tabular}{l}
|
|
56 |
\mbox{}\hspace{-1mm}\includegraphics[scale=0.36]{../pics/twitter.png}\\[-1mm]
|
|
57 |
\includegraphics[scale=0.30]{../pics/linked.png}\\
|
141
|
58 |
\includegraphics[scale=0.30]{../pics/guardian.jpg}\\[-3mm]
|
22
|
59 |
\mbox{}\hspace{-2mm}\includegraphics[scale=0.38]{../pics/morgan.png}\\[-3mm]
|
|
60 |
\includegraphics[scale=0.30]{../pics/suisse.png}\\
|
23
|
61 |
{\large\bf ...}
|
|
62 |
\end{tabular}
|
|
63 |
\end{textblock}
|
|
64 |
|
|
65 |
\begin{textblock}{6}(9,4)
|
|
66 |
\begin{tabular}{l}
|
22
|
67 |
\includegraphics[scale=0.20]{../pics/edf.png}\\[-1mm]
|
|
68 |
\includegraphics[scale=0.08]{../pics/novell.png}\\[-1mm]
|
|
69 |
\includegraphics[scale=0.30]{../pics/foursquare.png}\\
|
|
70 |
\includegraphics[scale=0.30]{../pics/hsbc.png}\\
|
|
71 |
{\large\bf ...}
|
|
72 |
\end{tabular}
|
|
73 |
\end{textblock}
|
|
74 |
|
|
75 |
\end{frame}
|
|
76 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
77 |
|
23
|
78 |
|
|
79 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
80 |
\begin{frame}[c]
|
|
81 |
\frametitle{Why Scala?}
|
|
82 |
|
|
83 |
\begin{itemize}
|
34
|
84 |
\item compiles to the JVM\\
|
|
85 |
\textcolor{gray}{(also JavaScript, native X86 in the works)}\medskip
|
32
|
86 |
\item integrates seamlessly with Java\medskip
|
33
|
87 |
\item combines \underline{\bf functional} and {\bf object-oriented} programming\bigskip
|
34
|
88 |
\item it is a bit on the ``mathematical'' side\\
|
|
89 |
\textcolor{gray}{(no pointers, no \texttt{null})}
|
|
90 |
|
33
|
91 |
\item often one can write very concise and elegant code
|
|
92 |
\end{itemize}\bigskip\medskip
|
|
93 |
|
|
94 |
\small
|
137
|
95 |
alternatives:\\
|
140
|
96 |
Elm, Haskell, Ocaml, F$\sharp$, Erlang, ML, Lisp (Racket), \ldots
|
23
|
97 |
|
|
98 |
\end{frame}
|
22
|
99 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
23
|
100 |
|
|
101 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
102 |
\begin{frame}[c]
|
32
|
103 |
\frametitle{Java vs Scala}
|
|
104 |
|
|
105 |
{\lstset{language=java}\fontsize{12}{12}\selectfont
|
|
106 |
\texttt{\lstinputlisting{Point.java}}}
|
|
107 |
|
33
|
108 |
\rule{11cm}{0.3mm}\\[-2mm]
|
|
109 |
|
32
|
110 |
{\lstset{language=scala}\fontsize{12}{12}\selectfont
|
|
111 |
\texttt{\lstinputlisting{Point.scala}}}
|
|
112 |
|
|
113 |
\begin{textblock}{6}(13,3)
|
|
114 |
\textbf{\large Java}
|
33
|
115 |
\end{textblock}
|
|
116 |
|
|
117 |
\begin{textblock}{6}(13,13.4)
|
32
|
118 |
\textbf{\large Scala}
|
|
119 |
\end{textblock}
|
|
120 |
|
|
121 |
\end{frame}
|
|
122 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
123 |
|
33
|
124 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
125 |
\begin{frame}[c]
|
137
|
126 |
\frametitle{First Steps: Scala Tools}
|
32
|
127 |
|
33
|
128 |
\begin{itemize}
|
|
129 |
\item there is a plugin for Eclipse (called Scala IDE)\medskip
|
137
|
130 |
\item there is also a plugin for IntelliJ\medskip
|
|
131 |
\item there is a worksheet mode in Eclipse and IntelliJ\bigskip
|
|
132 |
\item I use Sublime or venerable Emacs ;o)
|
33
|
133 |
\end{itemize}
|
|
134 |
|
|
135 |
\end{frame}
|
137
|
136 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
137 |
|
|
138 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
139 |
\begin{frame}[c]
|
|
140 |
\frametitle{\bf
|
|
141 |
\only<1>{\begin{tabular}{l}\\[2mm]Why Scala?\\ \mbox{}\end{tabular}}
|
|
142 |
\only<2->{\begin{tabular}{l}\\[2mm]Why Functional\\ Programming?\end{tabular}}
|
|
143 |
}
|
|
144 |
|
|
145 |
|
|
146 |
%
|
|
147 |
\mbox{}\\[3.5cm]
|
|
148 |
\small
|
140
|
149 |
Scala, Elm, Haskell, Ocaml, F$\sharp$, Erlang, ML, Lisp (Racket), \ldots
|
137
|
150 |
|
|
151 |
\only<3>{
|
|
152 |
\begin{textblock}{6}(2,6.2)
|
|
153 |
\begin{bubble}[10cm]
|
|
154 |
\normalsize``If you want to see which features will be in mainstream programming
|
|
155 |
languages tomorrow, then take a look at functional programming
|
|
156 |
languages today.''\medskip\small\\
|
|
157 |
\hfill{}---Simon Peyton Jones (works at Microsoft)\\
|
|
158 |
\hfill{}main developer of the Glasgow Haskell Compiler
|
|
159 |
\end{bubble}
|
|
160 |
\end{textblock}}
|
|
161 |
|
|
162 |
\end{frame}
|
|
163 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
164 |
|
|
165 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
166 |
\begin{frame}[c]
|
|
167 |
\mbox{}\\[-21mm]\mbox{}
|
|
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 |
\onslide<1-10>{
|
|
178 |
\node (A) at (0,0) [node]
|
|
179 |
{\mbox{\includegraphics[scale=0.15]{../pics/cplus2.jpg}}};
|
|
180 |
\node [above right] at (A.north west) {1986};}
|
|
181 |
|
|
182 |
\onslide<2->{
|
|
183 |
\node (B) at (3.5,0) [node]
|
|
184 |
{\mbox{\includegraphics[scale=0.15]{../pics/robotron.jpg}}};
|
|
185 |
\node [above right] at (B.north west) {1988, C};
|
|
186 |
\draw [->,line width=4mm] (A) -- (B);}
|
|
187 |
|
|
188 |
\onslide<3->{
|
|
189 |
\node (C0) at (6.3,0) {};
|
|
190 |
\node (C) at (8,0) [node]
|
|
191 |
{\mbox{\includegraphics[scale=0.15]{../pics/sun.jpg}}};
|
|
192 |
\node [above right] at (C.north west) {1992, {\small Linux}};
|
|
193 |
\draw [->,line width=4mm] (B) -- (C0);
|
|
194 |
\draw [->,line width=4mm] (C0) -- (C);}
|
|
195 |
|
|
196 |
\onslide<4->{
|
|
197 |
\node (D) at (8,-3.3) [node]
|
|
198 |
{\mbox{\includegraphics[scale=0.2]{../pics/gateway.jpg}}};
|
|
199 |
\draw [->,line width=4mm] (C) -- (D);
|
|
200 |
\node [below right] at (D.south west) {1996};}
|
|
201 |
|
|
202 |
\onslide<5->{
|
|
203 |
\node (E) at (4,-3.3) [node]
|
|
204 |
{\mbox{\includegraphics[scale=0.1]{../pics/appleg4.jpg}}};
|
|
205 |
\draw [->,line width=4mm] (D) -- (E);
|
|
206 |
\node [above right] at (E.north west) {2000};}
|
|
207 |
|
|
208 |
\onslide<6->{
|
|
209 |
\node (F0) at (1.5,-3.3) {};
|
|
210 |
\node (F1) at (1,-3.3) {};
|
|
211 |
\node (F) at (-0.9,-3.3) [node]
|
|
212 |
{\mbox{\includegraphics[scale=0.3]{../pics/appleair.png}}};
|
|
213 |
\draw [->,line width=4mm] (E) -- (F0);
|
|
214 |
\draw [->,line width=4mm] (F1) -- (F);
|
|
215 |
\node [above right] at (F.north west) {2012?};}
|
|
216 |
|
|
217 |
\onslide<7->{
|
|
218 |
\node (G) at (-0.9,-6.3) [node]
|
|
219 |
{\mbox{\includegraphics[scale=0.02]{../pics/applepro.jpg}}};
|
|
220 |
\draw [->,line width=4mm] (F) -- (G);
|
|
221 |
\node [right] at (G.west) {\hspace{22mm}2017};}
|
|
222 |
|
|
223 |
\end{tikzpicture}
|
|
224 |
\end{center}
|
|
225 |
|
|
226 |
|
|
227 |
\only<1>{%
|
|
228 |
\begin{textblock}{10}(2.5,5)
|
|
229 |
\includegraphics[scale=0.26]{../pics/cplus1.jpg}\\
|
|
230 |
\footnotesize 64K RAM, no HD, no monitor, lots of cables
|
|
231 |
\end{textblock}
|
|
232 |
\begin{textblock}{6}(10.9,4.5)
|
|
233 |
\includegraphics[scale=0.09]{../pics/mand1.png}
|
|
234 |
\includegraphics[scale=0.09]{../pics/mand2.png}
|
|
235 |
\end{textblock}
|
|
236 |
\begin{textblock}{6}(10.8,2.2)
|
|
237 |
\huge\bf 3 days
|
|
238 |
\end{textblock}
|
|
239 |
}
|
|
240 |
\only<8->{%
|
|
241 |
\begin{textblock}{8}(5.8,11.6)
|
|
242 |
\large\bf
|
|
243 |
\begin{tabular}{l@{}l}
|
|
244 |
1986:\, & no Internet\\
|
|
245 |
& no Amazon\\
|
|
246 |
& no FB, no mobiles,\ldots\\
|
|
247 |
\end{tabular}
|
|
248 |
\end{textblock}
|
|
249 |
}
|
|
250 |
\only<9>{
|
|
251 |
\begin{textblock}{1}(3,3)
|
|
252 |
\begin{bubble}[9cm]
|
|
253 |
\begin{tabular}{@{\hspace{8mm}}llll@{\hspace{8mm}}}
|
|
254 |
\\
|
|
255 |
\multicolumn{4}{c}{\bf Speedup by Moore's Law}\medskip\\
|
|
256 |
\textbf{1986:} & 3 days & \textbf{1996:} & 135 mins\\
|
|
257 |
\textbf{1988:} & 1.5 days & \textbf{1998:} & 67 mins\\
|
|
258 |
\textbf{1990:} & 18 hs & \textbf{2000:} & 33 mins\\
|
|
259 |
\textbf{1992:} & 9 hs & \textbf{2002:} & 16 mins\\
|
|
260 |
\textbf{1994:} & 4.5 hs & \multicolumn{2}{c}{???}\\
|
|
261 |
\\
|
|
262 |
\end{tabular}
|
|
263 |
\small Every two years, computers got twice as powerful.
|
|
264 |
\end{bubble}
|
|
265 |
\end{textblock}}
|
|
266 |
|
|
267 |
\end{frame}
|
|
268 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
269 |
|
|
270 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
271 |
\begin{frame}[c]
|
|
272 |
\frametitle{Seq vs Par}
|
|
273 |
|
|
274 |
\begin{center}
|
|
275 |
\begin{tabular}[t]{@{}l@{}l@{}}
|
|
276 |
\includegraphics[scale=0.14]{../pics/mand4.png} &
|
|
277 |
\raisebox{1.2mm}{\includegraphics[scale=0.14]{../pics/mand3.png}}
|
|
278 |
\end{tabular}
|
|
279 |
\end{center}
|
|
280 |
|
|
281 |
\only<2>{
|
|
282 |
\begin{textblock}{5}(12,2)
|
|
283 |
\begin{bubble}[2.1cm]
|
|
284 |
\footnotesize{}in Java or C++\\
|
|
285 |
\includegraphics[scale=0.50]{../pics/skeleton.jpg}\\
|
|
286 |
\end{bubble}
|
|
287 |
\end{textblock}}
|
|
288 |
|
|
289 |
\only<3>{
|
140
|
290 |
\begin{textblock}{14.2}(1,12.3)
|
|
291 |
In FP: Once a variable is created, it is assigned a value and then
|
|
292 |
never changed again $\Rightarrow$ no synchronisation\smallskip\\
|
|
293 |
\small\textcolor{gray}{(Andrew's second favourite feature of C++)}
|
137
|
294 |
\end{textblock}}
|
|
295 |
|
|
296 |
\end{frame}
|
|
297 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
298 |
|
|
299 |
|
|
300 |
|
32
|
301 |
|
|
302 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
303 |
\begin{frame}[c]
|
23
|
304 |
\frametitle{Types}
|
|
305 |
|
|
306 |
\begin{itemize}
|
33
|
307 |
\item Base types\smallskip
|
23
|
308 |
|
33
|
309 |
\begin{tabular}{@{}l@{}}
|
23
|
310 |
\textcolor{codegreen}{\texttt{Int}},
|
|
311 |
\textcolor{codegreen}{\texttt{Long}},
|
|
312 |
\textcolor{codegreen}{\texttt{BigInt}},
|
|
313 |
\textcolor{codegreen}{\texttt{Float}},
|
|
314 |
\textcolor{codegreen}{\texttt{Double}}\\
|
|
315 |
\textcolor{codegreen}{\texttt{String}},
|
25
|
316 |
\textcolor{codegreen}{\texttt{Char}}\\
|
|
317 |
\textcolor{codegreen}{\texttt{Boolean}}
|
23
|
318 |
\end{tabular}
|
|
319 |
|
33
|
320 |
\item Compound types \smallskip
|
23
|
321 |
|
33
|
322 |
\begin{tabular}{@{}ll@{}}
|
23
|
323 |
\textcolor{codegreen}{\texttt{List[Int]}} & lists of Int's \\
|
|
324 |
\textcolor{codegreen}{\texttt{Set[Double]}} & sets of Double's \\
|
|
325 |
\textcolor{codegreen}{\texttt{(Int, String)}} & Int-String pair\\
|
|
326 |
\textcolor{codegreen}{\texttt{List[(BigInt, String)]}} &
|
|
327 |
lists of BigInt-String\\
|
|
328 |
& pairs\\
|
26
|
329 |
\textcolor{codegreen}{\texttt{List[List[Int]]}} & list of lists of Int's\\
|
23
|
330 |
\end{tabular}
|
|
331 |
|
|
332 |
\end{itemize}
|
|
333 |
|
|
334 |
\end{frame}
|
|
335 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
336 |
|
32
|
337 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
338 |
\begin{frame}[c]
|
|
339 |
\frametitle{An Http Request}
|
|
340 |
|
|
341 |
\begin{textblock}{1}(2,5)
|
|
342 |
\begin{tabular}{c}
|
|
343 |
\includegraphics[scale=0.15]{../pics/servers.png}\\[-2mm]
|
|
344 |
\small Server
|
|
345 |
\end{tabular}
|
|
346 |
\end{textblock}
|
|
347 |
|
|
348 |
\begin{textblock}{1}(5.6,4)
|
|
349 |
\begin{tikzpicture}[scale=1.1]
|
|
350 |
\draw[white] (0,1) node (X) {};
|
|
351 |
\draw[white] (2,1) node (Y) {};
|
|
352 |
\draw[white] (0,0) node (X1) {};
|
|
353 |
\draw[white] (2,0) node (Y1) {};
|
|
354 |
\draw[white] (0,-1) node (X2) {};
|
|
355 |
\draw[white] (2,-1) node (Y2) {};
|
|
356 |
\draw[red, <-, line width = 2mm] (X) -- (Y);
|
|
357 |
\node [inner sep=5pt,label=above:\textcolor{black}{GET request}] at ($ (X)!.5!(Y) $) {};
|
|
358 |
\draw[red, ->, line width = 2mm] (X1) -- (Y1);
|
|
359 |
\node [inner sep=5pt,label=above:\textcolor{black}{webpage}] at ($ (X1)!.5!(Y1) $) {};
|
|
360 |
\draw[red, <-, line width = 2mm] (X2) -- (Y2);
|
|
361 |
\node [inner sep=7pt,label=above:\textcolor{black}{POST data}] at ($ (X2)!.5!(Y2) $) {};
|
|
362 |
\end{tikzpicture}
|
|
363 |
\end{textblock}
|
|
364 |
|
|
365 |
|
|
366 |
\begin{textblock}{1}(9,5.5)
|
|
367 |
\begin{tabular}{c}
|
|
368 |
\includegraphics[scale=0.15]{../pics/laptop.png}\\[-2mm]
|
|
369 |
\small Browser
|
|
370 |
\end{tabular}
|
|
371 |
\end{textblock}
|
|
372 |
\end{frame}
|
|
373 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
374 |
|
|
375 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
376 |
\begin{frame}[c]
|
|
377 |
|
|
378 |
{\lstset{language=Java}\fontsize{7}{8}\selectfont
|
|
379 |
\texttt{\lstinputlisting{URLReader.java}}}
|
|
380 |
|
|
381 |
\end{frame}
|
|
382 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
383 |
|
33
|
384 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
385 |
\begin{frame}[c]
|
140
|
386 |
\frametitle{Coursework}
|
|
387 |
|
|
388 |
\begin{itemize}
|
|
389 |
\item sorry, I might have been a bit wordy:\\
|
|
390 |
CW description is 7 pages, but
|
|
391 |
I only needed \mbox{< 100} loc for all the CW\bigskip
|
|
392 |
|
|
393 |
\item there is email feedback when pushing code to github\bigskip
|
|
394 |
|
|
395 |
\item we want you to learn FP: \alert{no vars}, no mutable
|
|
396 |
datastructures, e.g.~\texttt{ListBuffer}
|
|
397 |
\end{itemize}
|
|
398 |
\end{frame}
|
|
399 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
400 |
|
|
401 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
402 |
|
|
403 |
\begin{frame}[c, fragile]
|
|
404 |
\frametitle{The Joy of Immutability}
|
|
405 |
|
|
406 |
\begin{itemize}
|
|
407 |
\item If you need to manipulate some data in a list say, then you make
|
|
408 |
a new list with the updated values, rather than revise the original
|
|
409 |
list. Easy!\medskip
|
|
410 |
|
|
411 |
{\small
|
|
412 |
\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
|
|
413 |
val old_list = List(1, 2, 3, 5)
|
|
414 |
val new_list = 0 :: old_list
|
|
415 |
\end{lstlisting}}
|
|
416 |
|
|
417 |
\item You do not have to be defensive about who can access the data
|
|
418 |
(concurrency, lazyness).
|
|
419 |
\end{itemize}
|
|
420 |
\end{frame}
|
|
421 |
|
|
422 |
|
|
423 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
424 |
|
|
425 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
426 |
\begin{frame}[t]
|
|
427 |
\frametitle{Email: Hate 'val'}
|
|
428 |
|
|
429 |
\mbox{}\\[-25mm]\mbox{}
|
|
430 |
|
|
431 |
\begin{center}
|
|
432 |
\begin{bubble}[10.5cm]
|
|
433 |
Subject: \textbf{Hate '\textbf{\texttt{val}}'}\hfill 01:00 AM\medskip\\
|
|
434 |
|
|
435 |
Hello Mr Urban,\medskip\\
|
|
436 |
|
|
437 |
I just wanted to ask, how are we suppose to work
|
|
438 |
with the completely useless \textbf{\texttt{val}}, that can’t be changed ever? Why is
|
|
439 |
this rule active at all? I’ve spent 4 hours not thinking on the
|
|
440 |
coursework, but how to bypass this annoying rule. What’s the whole
|
|
441 |
point of all these coursework, when we can’t use everything Scala
|
|
442 |
gives us?!?\medskip\\
|
|
443 |
|
|
444 |
Regards.\\
|
|
445 |
\mbox{}\hspace{5mm}\textcolor{black!50}{<<deleted>>}\\
|
|
446 |
\end{bubble}
|
|
447 |
\end{center}
|
|
448 |
|
|
449 |
\end{frame}
|
|
450 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
451 |
|
|
452 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
453 |
\begin{frame}[c]
|
|
454 |
|
|
455 |
\mbox{}\\[-25mm]\mbox{}
|
|
456 |
|
|
457 |
\begin{center}
|
|
458 |
\begin{bubble}[10.5cm]
|
|
459 |
Subject: \textbf{Re: Hate '\textbf{\texttt{val}}'}\hfill 01:02 AM\bigskip\bigskip\\
|
|
460 |
|
|
461 |
\textcolor{black!70}{
|
|
462 |
\textit{\large<<my usual rant about fp\ldots\\ concurrency bla bla\ldots{} better programs
|
|
463 |
yada>>}}\bigskip\bigskip\bigskip
|
|
464 |
|
|
465 |
PS: What are you trying to do where you desperately want to use \texttt{var}?
|
|
466 |
\end{bubble}
|
|
467 |
\end{center}
|
|
468 |
|
|
469 |
\end{frame}
|
|
470 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
471 |
|
|
472 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
473 |
\begin{frame}[c,fragile]
|
|
474 |
|
|
475 |
\begin{textblock}{6}(0.5,0.5)
|
|
476 |
\begin{bubble}[11.5cm]
|
|
477 |
\small
|
|
478 |
Subject: \textbf{Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:04 AM\medskip\\
|
|
479 |
|
|
480 |
\textbf{Right now my is\_legal function works fine:}
|
|
481 |
|
|
482 |
\footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
|
|
483 |
def is_legal(dim: Int, path: Path)(x: Pos): Boolean = {
|
|
484 |
var boolReturn = false
|
|
485 |
if(x._1 > dim || x._2 > dim || x._1 < 0 || x._2 < 0) {
|
|
486 |
else { var breakLoop = false
|
|
487 |
if(path == Nil) { boolReturn = true }
|
|
488 |
else { for(i <- 0 until path.length) {
|
|
489 |
if(breakLoop == false) {
|
|
490 |
if(path(i) == x) {
|
|
491 |
boolReturn = true
|
|
492 |
breakLoop = true
|
|
493 |
}
|
|
494 |
else { boolReturn = false }
|
|
495 |
} else breakLoop
|
|
496 |
}
|
|
497 |
}
|
|
498 |
boolReturn
|
|
499 |
}
|
|
500 |
\end{lstlisting}
|
|
501 |
\end{bubble}
|
|
502 |
\end{textblock}
|
|
503 |
|
|
504 |
\begin{textblock}{6}(8.2,11.8)
|
|
505 |
\begin{bubble}[5.5cm]\footnotesize\bf
|
|
506 |
\ldots{}but I can’t make it work with boolReturn being val. What approach would
|
|
507 |
you recommend in this case, and is using var in this case justified?
|
|
508 |
\end{bubble}
|
|
509 |
\end{textblock}
|
|
510 |
|
|
511 |
\only<2>{
|
|
512 |
\begin{textblock}{6}(0.3,11.8)
|
|
513 |
\begin{bubble}[3.1cm]
|
|
514 |
\textbf{Me:}
|
|
515 |
\raisebox{-12mm}{\includegraphics[scale=0.08]{../pics/throwup.jpg}}
|
|
516 |
\end{bubble}
|
|
517 |
\end{textblock}}
|
|
518 |
|
|
519 |
\end{frame}
|
|
520 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
521 |
|
|
522 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
523 |
\begin{frame}[t,fragile]
|
|
524 |
|
|
525 |
\mbox{}\\[-25mm]\mbox{}
|
|
526 |
|
|
527 |
\begin{textblock}{6}(0.5,2)
|
|
528 |
\begin{bubble}[11.5cm]
|
|
529 |
Subject: \textbf{Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:06 AM\bigskip\\
|
|
530 |
\small
|
|
531 |
|
|
532 |
OK. So you want to make sure that the \texttt{x}-position is not outside the
|
|
533 |
board....and furthermore you want to make sure that the \texttt{x}-position
|
|
534 |
is not yet in the path list. How about something like\bigskip
|
|
535 |
|
|
536 |
\footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
|
|
537 |
def is_legal(dim: Int, path: Path)(x: Pos): Boolean =
|
|
538 |
...<<some board conditions>>... && !path.contains(x)
|
|
539 |
\end{lstlisting}\bigskip
|
|
540 |
|
|
541 |
\small Does not even contain a \texttt{val}.
|
|
542 |
\end{bubble}
|
|
543 |
\end{textblock}
|
|
544 |
|
|
545 |
\begin{textblock}{6}(7,12)
|
|
546 |
\footnotesize\textcolor{black!50}{(This is all on one line)}
|
|
547 |
\end{textblock}
|
|
548 |
|
|
549 |
\end{frame}
|
|
550 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
551 |
|
|
552 |
|
|
553 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
554 |
\begin{frame}[t,fragile]
|
|
555 |
|
|
556 |
\mbox{}\\[-15mm]\mbox{}
|
|
557 |
|
|
558 |
\begin{textblock}{6}(1,3)
|
|
559 |
\begin{bubble}[10.5cm]
|
|
560 |
Subject: \textbf{Re: Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 11:02 AM\bigskip\bigskip\\
|
|
561 |
|
|
562 |
THANK YOU! You made me change my coding perspective. Because of you,
|
|
563 |
I figured out the next one\ldots
|
|
564 |
\end{bubble}
|
|
565 |
\end{textblock}
|
|
566 |
|
|
567 |
\only<2>{
|
|
568 |
\begin{textblock}{6}(0.3,11.8)
|
|
569 |
\begin{bubble}[3.1cm]
|
|
570 |
\textbf{Me:}
|
|
571 |
\raisebox{-12mm}{\includegraphics[scale=0.15]{../pics/happy.jpg}}
|
|
572 |
\end{bubble}
|
|
573 |
\end{textblock}}
|
|
574 |
|
|
575 |
\end{frame}
|
|
576 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
577 |
|
|
578 |
|
|
579 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
580 |
\begin{frame}[c]
|
33
|
581 |
\frametitle{Conclusion}
|
|
582 |
|
|
583 |
\begin{itemize}
|
|
584 |
\item Scala is still under heavy development\\ (the compiler is terribly slow)\medskip
|
|
585 |
\item {\bf\url{http://www.scala-lang.org/}}\bigskip
|
140
|
586 |
|
|
587 |
\item it is a rather \textbf{\alert{deep}} language\ldots i.e.~gives
|
|
588 |
you a lot of rope to shoot yourself\bigskip
|
33
|
589 |
|
140
|
590 |
\item learning functional programming is not easy\ldots{}when you have
|
|
591 |
spent all of your career thinking in a procedural way it is hard to
|
|
592 |
change\bigskip\medskip
|
|
593 |
|
33
|
594 |
\item hope you have fun with the coursework
|
|
595 |
\end{itemize}
|
|
596 |
\end{frame}
|
|
597 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
598 |
|
|
599 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
600 |
\begin{frame}[c]
|
140
|
601 |
\frametitle{\begin{tabular}{c}\\[0cm]\alert{Questions?}\end{tabular}}
|
33
|
602 |
|
140
|
603 |
\begin{center}
|
|
604 |
\begin{tabular}[t]{@{}l@{}l@{}}
|
|
605 |
\includegraphics[scale=0.1]{../pics/mand4.png} &
|
|
606 |
\raisebox{1.2mm}{\includegraphics[scale=0.1]{../pics/mand3.png}}
|
|
607 |
\end{tabular}
|
|
608 |
\end{center}
|
|
609 |
|
|
610 |
\begin{center}
|
|
611 |
My Scala Office Hours: Thursdays 11 -- 13
|
|
612 |
\end{center}
|
33
|
613 |
\end{frame}
|
|
614 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
615 |
\end{document}
|
32
|
616 |
|
|
617 |
|
22
|
618 |
\end{document}
|
|
619 |
|
|
620 |
%%% Local Variables:
|
|
621 |
%%% mode: latex
|
|
622 |
%%% TeX-master: t
|
|
623 |
%%% End:
|
|
624 |
|
140
|
625 |
|
|
626 |
“Functional programming is often regarded as the best-kept secret of
|
|
627 |
scientific modelers, mathematicians, artificial intelligence
|
|
628 |
researchers, financial institutions, graphic designers, CPU designers,
|
|
629 |
compiler programmers, and telecommunications engineers.”
|
|
630 |
|
|
631 |
The Wikipedia F# page |