87 |
35 |
88 \normalsize |
36 \normalsize |
89 \begin{center} |
37 \begin{center} |
90 \begin{tabular}{ll} |
38 \begin{tabular}{ll} |
91 Email: & christian.urban at kcl.ac.uk\\ |
39 Email: & christian.urban at kcl.ac.uk\\ |
92 Office: & N\liningnums{7.07} (North Wing, Bush House)\\ |
40 Office: & N\liningnums{7.07} (North Wing, Bush House)\bigskip\\ |
93 Slides \& Code: & KEATS\medskip\\ |
41 Slides \& Code: & KEATS\\ |
94 Office Hours: & Mondays 12:00 -- 14:00\\ |
42 & \onslide<2>{\alert{PDF: A Crash-Course in Scala}}\bigskip\\ |
|
43 Office Hours: & Thursdays 12:00 -- 14:00\\ |
|
44 Additionally: & (for Scala) Tuesdays 10:45 -- 11:45\\ |
95 \end{tabular} |
45 \end{tabular} |
96 \end{center} |
46 \end{center} |
97 |
47 |
98 |
48 \end{frame} |
99 \end{frame} |
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
50 |
101 |
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
52 |
103 |
53 \begin{frame}[c] |
104 \begin{frame}[c] |
54 \frametitle{Marks for Preliminary 8} |
105 \frametitle{Marks for CW7 (Part 1 + 2)} |
55 |
106 |
56 Raw marks (265 submissions):\bigskip |
107 Raw marks (234 submissions): |
57 |
108 |
58 \begin{itemize} |
109 \begin{itemize} |
59 \item 4\%: \hspace{4mm}211 |
110 \item 6\%: \hspace{4mm}192 students |
60 \item 3\%: \hspace{4mm}11 |
111 \item 5\%: \hspace{4mm}16 |
61 \item 2\%: \hspace{4mm}14 |
112 \item 4\%: \hspace{4mm}7 |
62 \item 1\%: \hspace{4mm}8 |
113 \item 3\%: \hspace{4mm}2 |
63 \item 0\%: \hspace{4mm}21 |
114 \item 2\%: \hspace{4mm}6 |
64 \end{itemize}\bigskip\bigskip |
115 \item 1\%: \hspace{4mm}1 |
65 |
116 \item 0\%: \hspace{4mm}9 |
66 \footnotesize |
117 \end{itemize} |
67 (plagiarism/collusion interviews ongoing again!) |
118 \end{frame} |
68 |
119 |
69 \end{frame} |
120 |
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
71 |
122 |
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
123 |
73 |
124 |
74 \begin{frame}[c] |
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
75 \frametitle{Plan for Today} |
|
76 |
|
77 \begin{itemize} |
|
78 \item Being Lazy |
|
79 \item Polymorphic Types |
|
80 \item Immutable OOP |
|
81 \item Making Fun about Scala |
|
82 \end{itemize} |
|
83 |
|
84 \end{frame} |
|
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
86 |
|
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
126 \begin{frame}[c,fragile] |
88 \begin{frame}[c,fragile] |
|
89 \frametitle{How To calcululate 100 Mio Collatz Series?} |
|
90 |
|
91 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=1mm] |
|
92 (1L to 100_000_000).map(collatz).max |
|
93 \end{lstlisting} |
|
94 |
|
95 \end{frame} |
|
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
97 |
|
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
99 \begin{frame}[c,fragile] |
|
100 \frametitle{Polyorphic Types} |
|
101 |
|
102 To be avoided:\bigskip\bigskip |
127 \small |
103 \small |
128 |
104 |
129 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-7mm] |
105 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-6mm] |
130 def get_csv_url(url: String) : List[String] = { |
106 def length_string_list(lst: List[String]): Int = |
131 val csv = Try(Source.fromURL(url)).getOrElse(null) |
107 lst match { |
132 if (csv == null){ |
108 case Nil => 0 |
133 List() |
109 case x::xs => 1 + length_string_list(xs) |
134 } |
110 } |
135 else { |
111 |
136 .... |
112 |
137 } |
113 def length_int_list(lst: List[Int]): Int = |
|
114 lst match { |
|
115 case Nil => 0 |
|
116 case x::xs => 1 + length_int_list(xs) |
|
117 } |
|
118 \end{lstlisting} |
|
119 |
|
120 \end{frame} |
|
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
122 |
|
123 |
|
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
125 \begin{frame}[c,fragile] |
|
126 \frametitle{Polyorphic Types} |
|
127 |
|
128 \small |
|
129 |
|
130 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-6mm] |
|
131 def length[A](lst: List[A]): Int = lst match { |
|
132 case Nil => 0 |
|
133 case x::xs => 1 + length(xs) |
138 } |
134 } |
|
135 |
|
136 length(List("1", "2", "3", "4")) |
|
137 length(List(1, 2, 3, 4)) |
|
138 |
|
139 |
|
140 def map[A, B](lst: List[A], f: A => B): List[B] = |
|
141 lst match { |
|
142 case Nil => Nil |
|
143 case x::xs => f(x)::map(xs, f) |
|
144 } |
139 \end{lstlisting} |
145 \end{lstlisting} |
140 |
146 \end{frame} |
141 \pause |
147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
142 \bigskip |
148 |
143 \rule{11cm}{0.3mm} |
149 |
144 \bigskip |
150 |
145 |
151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
146 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-7mm] |
152 \begin{frame}[c] |
147 def get_csv_url(url: String) : List[String] = { |
153 \frametitle{DFAs} |
148 Try(Source.fromURL(url)....).getOrElse(Nil) |
154 |
149 \end{lstlisting} |
155 \begin{center} |
150 |
156 \begin{tikzpicture}[>=stealth',very thick,auto, |
151 |
157 every state/.style={minimum size=0pt,inner sep=2pt, |
152 \end{frame} |
158 draw=blue!50,very thick,fill=blue!20},] |
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
159 |
154 |
160 \only<1,3->{\node[state,initial] (Q_0) {$\mbox{Q}_0$};} |
155 |
161 \only<2>{\node[state,initial,fill=red] (Q_0) {$\mbox{Q}_0$};} |
156 |
162 \only<1,2,4->{\node[state] (Q_1) [right=of Q_0] {$\mbox{Q}_1$};} |
157 |
163 \only<3>{\node[state,fill=red] (Q_1) [right=of Q_0] {$\mbox{Q}_1$};} |
158 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
164 \only<-3,5->{\node[state] (Q_2) [below right=of Q_0] {$\mbox{Q}_2$};} |
159 \begin{frame}[c,fragile] |
165 \only<4>{\node[state,fill=red] (Q_2) [below right=of Q_0] {$\mbox{Q}_2$};} |
|
166 \only<-4,6->{\node[state] (Q_3) [right=of Q_2] {$\mbox{Q}_3$};} |
|
167 \only<5>{\node[state,fill=red] (Q_3) [right=of Q_2] {$\mbox{Q}_3$};} |
|
168 \only<-5>{\node[state, accepting] (Q_4) [right=of Q_1] {$\mbox{Q}_4$};} |
|
169 \only<6->{\node[state, accepting,fill=red] (Q_4) [right=of Q_1] {$\mbox{Q}_4$};} |
|
170 |
|
171 \path[->] (Q_0) edge node [above] {\alert{$a$}} (Q_1); |
|
172 \path[->] (Q_1) edge node [above] {\alert{$a$}} (Q_4); |
|
173 \path[->] (Q_4) edge [loop right] node {\alert{$a, b$}} (); |
|
174 \path[->] (Q_3) edge node [right] {\alert{$a$}} (Q_4); |
|
175 \path[->] (Q_2) edge node [above] {\alert{$a$}} (Q_3); |
|
176 \path[->] (Q_1) edge node [right] {\alert{$b$}} (Q_2); |
|
177 \path[->] (Q_0) edge node [above] {\alert{$b$}} (Q_2); |
|
178 \path[->] (Q_2) edge [loop left] node {\alert{$b$}} (); |
|
179 \path[->] (Q_3) edge [bend left=95, looseness=1.3] node [below] {\alert{$b$}} (Q_0); |
|
180 \end{tikzpicture} |
|
181 \end{center} |
|
182 |
|
183 \begin{textblock}{9}(4,12) |
|
184 \LARGE{} |
|
185 \only<3->{\boldmath\alert{$a$}}% |
|
186 \only<4->{\boldmath\alert{$b$}}% |
|
187 \only<5->{\boldmath\alert{$a$}}% |
|
188 \only<6->{\boldmath\alert{$a$}}% |
|
189 \only<7->{\boldmath\alert{$a\quad\Rightarrow \textbf{yes}$}}% |
|
190 \end{textblock} |
|
191 |
|
192 \end{frame} |
|
193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
194 |
|
195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
196 \begin{frame}[t] |
|
197 \frametitle{DFAs} |
|
198 |
|
199 A \alert{\bf deterministic finite automaton} (DFA) consists of |
|
200 5 things: |
|
201 |
|
202 \begin{itemize} |
|
203 \item an alphabet \bl{$\varSigma$} |
|
204 \item a set of states \bl{$\mbox{Qs}$} |
|
205 \item one of these states is the start state \bl{$\mbox{Q}_0$} |
|
206 \item some states are accepting states \bl{$F$}, and |
|
207 \item there is transition function \bl{$\delta$}\bigskip |
|
208 |
160 \small |
209 \small |
161 |
210 which takes a state and a character as arguments and produces a |
162 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-7mm] |
211 new state; this function might not be everywhere defined |
163 def get_csv_url(url: String) : List[String] = { |
212 \end{itemize} |
164 try { |
213 |
165 val csvFile = Source.fromURL(url) |
214 \begin{center} |
166 .... |
215 \bl{$A(\varSigma, \mbox{Qs}, \mbox{Q}_0, F, \delta)$} |
167 } catch { |
216 \end{center} |
168 case unknown : Throwable => List() |
217 |
169 } |
218 \end{frame} |
170 } |
219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
171 \end{lstlisting} |
220 |
172 |
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
173 |
222 \begin{frame}[c] |
174 \bigskip |
223 \frametitle{NFAs} |
175 \rule{11cm}{0.3mm} |
224 |
176 \bigskip |
225 \begin{center} |
177 |
226 \begin{tikzpicture}[>=stealth',very thick, auto, |
178 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-7mm] |
227 every state/.style={minimum size=0pt,inner sep=3pt, |
179 def get_csv_url(url: String) : List[String] = { |
228 draw=blue!50,very thick,fill=blue!20},scale=2] |
180 Try(Source.fromURL(url)....).getOrElse(Nil) |
229 \node[state,initial] (Q_0) {$\mbox{Q}_0$}; |
181 \end{lstlisting} |
230 \node[state] (Q_1) [right=of Q_0] {$\mbox{Q}_1$}; |
182 |
231 \node[state, accepting] (Q_2) [right=of Q_1] {$\mbox{Q}_2$}; |
183 |
232 \path[->] (Q_0) edge [loop above] node {\alert{$b$}} (); |
184 \end{frame} |
233 \path[<-] (Q_0) edge node [below] {\alert{$b$}} (Q_1); |
185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
234 \path[->] (Q_0) edge [bend left] node [above] {\alert{$a$}} (Q_1); |
|
235 \path[->] (Q_0) edge [bend right=45,looseness=1.3] node [below] {\alert{$a$}} (Q_2); |
|
236 \path[->] (Q_1) edge [loop above] node {\alert{$a,b$}} (); |
|
237 \path[->] (Q_1) edge node [above] {\alert{$a$}} (Q_2); |
|
238 \end{tikzpicture} |
|
239 \end{center} |
|
240 |
|
241 \end{frame} |
|
242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
243 |
|
244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
245 \tikzstyle{sensor}=[draw, fill=blue!20, text width=3.8em, line width=1mm, |
|
246 text centered, minimum height=2em,drop shadow] |
|
247 \tikzstyle{ann} = [above, text width=4em, text centered] |
|
248 \tikzstyle{sc} = [sensor, text width=7em, fill=red!20, |
|
249 minimum height=6em, rounded corners, drop shadow,line width=1mm] |
|
250 |
|
251 \begin{frame}[fragile,c] |
|
252 \frametitle{Compilers 6CCS3CFL} |
|
253 |
|
254 \begin{tikzpicture} |
|
255 % Validation Layer is the same except that there are a set of nodes and links which are added |
|
256 |
|
257 \path (0,0) node (IR) [sc] {\textbf{WHILE Language}\\ compiler}; |
|
258 \path (IR.west)+(-2.2,1.7) node (sou1) [sensor] {Fact}; |
|
259 \path (IR.west)+(-2.2,0.5) node (sou2)[sensor] {Fib}; |
|
260 \path (IR.west)+(-2.2,-0.7) node (sou4)[sensor] {Primes}; |
|
261 \only<2>{\path (IR.west)+(-2.2,-1.9) node (sou3)[sensor] {BrainF**k};} |
|
262 |
|
263 \path [draw,->,line width=1mm] (sou1.east) -- node [above] {} (IR.160); |
|
264 \path [draw,->,line width=1mm] (sou2.east) -- node [above] {} (IR.180); |
|
265 \only<2>{\path [draw,->,line width=1mm] (sou3.east) -- node [above] {} (IR.200);} |
|
266 \path [draw,->,line width=1mm] (sou4.east) -- node [above] {} (IR.190); |
|
267 |
|
268 \path (IR.east)+(2.2, 0.8) node (tar2)[sensor] {JVM}; |
|
269 \path (IR.east)+(2.2,-0.8) node (tar3)[sensor] {LLVM{\small(x86)}}; |
|
270 |
|
271 \path [draw,<-,line width=1mm] (tar2.west) -- node [above] {} (IR.5); |
|
272 \path [draw,<-,line width=1mm] (tar3.west) -- node [above] {} (IR.-5); |
|
273 |
|
274 |
|
275 \end{tikzpicture} |
|
276 \end{frame} |
|
277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
278 |
186 |
279 |
187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
188 \begin{frame}[c] |
281 \begin{frame}[c] |
189 \frametitle{Dijkstra on Testing} |
282 \frametitle{Dijkstra on Testing} |
190 |
283 |
292 \end{textblock}} |
385 \end{textblock}} |
293 |
386 |
294 \end{frame} |
387 \end{frame} |
295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
296 |
389 |
297 |
|
298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
299 \begin{frame}[c] |
|
300 \frametitle{CW9 : Regexes} |
|
301 |
|
302 \begin{center} |
|
303 Graphs: $(a^*)^* b$ and strings $\underbrace{\;a\ldots a\;}_{n}$\bigskip |
|
304 |
|
305 \begin{tabular}[t]{@{\hspace{-8mm}}c@{\hspace{-4mm}}c@{}} |
|
306 \raisebox{6mm}{\begin{tikzpicture} |
|
307 \begin{axis}[ |
|
308 xlabel={$n$}, |
|
309 x label style={at={(1.05,0.0)}}, |
|
310 ylabel={time in secs}, |
|
311 enlargelimits=false, |
|
312 xtick={0,5,...,30}, |
|
313 xmax=33, |
|
314 ymax=35, |
|
315 ytick={0,5,...,30}, |
|
316 scaled ticks=false, |
|
317 axis lines=left, |
|
318 width=5.5cm, |
|
319 height=5cm, |
|
320 legend entries={Python, Java 8}, |
|
321 legend pos=north west, |
|
322 legend cell align=left] |
|
323 \addplot[blue,mark=*, mark options={fill=white}] table {re-python2.data}; |
|
324 \addplot[cyan,mark=*, mark options={fill=white}] table {re-java.data}; |
|
325 \end{axis} |
|
326 \end{tikzpicture}} |
|
327 & |
|
328 \onslide<1>{\begin{tikzpicture} |
|
329 \begin{axis}[ |
|
330 xlabel={$n$}, |
|
331 x label style={at={(1.05,0.0)}}, |
|
332 ylabel={time in secs}, |
|
333 enlargelimits=false, |
|
334 ymax=35, |
|
335 ytick={0,5,...,30}, |
|
336 axis lines=left, |
|
337 %%scaled ticks=false, |
|
338 width=5.5cm, |
|
339 height=5cm] |
|
340 %%\addplot[green,mark=square*,mark options={fill=white}] table {re2a.data}; |
|
341 \addplot[red,mark=square*,mark options={fill=white}] table {re3a.data}; |
|
342 \end{axis} |
|
343 \end{tikzpicture}} |
|
344 \end{tabular} |
|
345 \end{center} |
|
346 |
|
347 |
|
348 \small |
|
349 \hfill Kuklewicz: most POSIX matchers are buggy\\ |
|
350 \footnotesize |
|
351 \hfill \url{http://www.haskell.org/haskellwiki/Regex_Posix} |
|
352 \end{frame} |
|
353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
354 |
391 |
355 \begin{frame}[c] |
392 \begin{frame}[c] |
356 \frametitle{Where to go on from here?} |
393 \frametitle{Where to go on from here?} |
357 |
394 |
358 \begin{itemize} |
395 \begin{itemize} |
359 \item Martin Odersky (EPFL)\ldots he is currently throwing out everything |
396 \item Martin Odersky (EPFL)\ldots he is currently throwing out everything |
360 and starts again with the dotty compiler for Scala\medskip |
397 and starts again with the dotty compiler for Scala 3.0\medskip |
361 |
398 |
362 \item Elm (\url{http://elm-lang.org})\ldots web applications with style\medskip |
399 \item Elm (\url{http://elm-lang.org})\ldots web applications with style\medskip |
363 |
400 |
364 \item Haskell, Ocaml, Standard ML, Scheme, \ldots |
401 \item Haskell, Ocaml, Standard ML, Scheme, \ldots |
365 \end{itemize} |
402 \end{itemize} |