44 |
44 |
45 \normalsize |
45 \normalsize |
46 \begin{center} |
46 \begin{center} |
47 \begin{tabular}{ll} |
47 \begin{tabular}{ll} |
48 Email: & christian.urban at kcl.ac.uk\\ |
48 Email: & christian.urban at kcl.ac.uk\\ |
49 Office: & N\liningnums{7.07} (North Wing, Bush House)\bigskip\\ |
49 %Office: & N\liningnums{7.07} (North Wing, Bush House)\bigskip\\ |
50 Slides \& Code: & KEATS\bigskip\\ |
50 Slides \& Code: & KEATS\bigskip\\ |
51 Office Hours: & Thursdays 12:00 -- 14:00\\ |
51 %Office Hours: & Thursdays 12:00 -- 14:00\\ |
52 Additionally: & (for Scala) Tuesdays 10:45 -- 11:45\\ |
52 %Additionally: & (for Scala) Tuesdays 10:45 -- 11:45\\ |
53 \end{tabular} |
53 \end{tabular} |
54 \end{center} |
54 \end{center} |
55 |
55 |
56 |
56 |
57 \end{frame} |
57 \end{frame} |
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
59 |
59 |
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
60 |
61 \begin{frame}[c,fragile] |
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
62 \frametitle{Scala 2.13.1} |
62 \begin{frame}[t,fragile] |
63 |
63 \frametitle{For-Comprehensions} |
64 \begin{lstlisting}[language={},numbers=none, |
64 |
65 basicstyle=\ttfamily\small,xleftmargin=-2mm] |
65 %\small |
66 $ scala |
66 \begin{lstlisting}[language=Scala,numbers=none] |
67 |
67 for (n <- List(1, 2, 3, 4, 5)) yield n * n |
68 Welcome to Scala 2.13.1 (Java HotSpot(TM) |
68 \end{lstlisting} |
69 64-Bit Server VM, Java 9). Type in expressions |
69 |
70 for evaluation. Or try :help. |
70 \begin{textblock}{5}(2,6) |
71 |
71 \includegraphics[scale=0.3]{../pics/fun.png} |
72 scala> |
72 \end{textblock} |
73 \end{lstlisting}%$ |
73 |
74 \bigskip\bigskip |
74 \begin{textblock}{5}(9,6) |
75 |
75 \includegraphics[scale=0.3]{../pics/fun.png} |
76 With older versions you will get strange results with my reference implementation. |
76 \end{textblock} |
77 |
77 |
78 \end{frame} |
78 |
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
79 \end{frame} |
80 |
80 |
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
81 |
82 \begin{frame}[c,fragile] |
|
83 \frametitle{Reference Implementation} |
|
84 |
|
85 Keep your implementation and my reference implementation separate.\bigskip |
|
86 |
|
87 \begin{lstlisting}[language={},numbers=none, |
|
88 basicstyle=\ttfamily\small,xleftmargin=-2mm] |
|
89 $ scala -cp collatz.jar |
|
90 |
|
91 scala> CW6a.collatz(6) |
|
92 res0: Long = 8 |
|
93 |
|
94 |
|
95 scala> import CW6a._ |
|
96 scala> collatz(9) |
|
97 res1: Long = 19 |
|
98 \end{lstlisting}%$ |
|
99 |
|
100 \end{frame} |
|
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
102 |
|
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
104 \begin{frame}[t] |
83 \begin{frame}[t] |
105 \frametitle{Preliminary Part 7} |
84 \frametitle{For-Comprehensions} |
106 |
|
107 \Large |
|
108 \[ |
|
109 \texttt{overlap}(d_1, d_2) = \frac{d_1 \cdot d_2}{max(d_1^2, d_2^2)} |
|
110 \]\bigskip |
|
111 |
|
112 \large |
|
113 \quad{}\;where \;$d_1^2$\; means \;$d_1 \cdot d_1$\; and so on |
|
114 \end{frame} |
|
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
116 |
|
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
118 \begin{frame}[c] |
|
119 \frametitle{Discussion Forum} |
|
120 |
|
121 \large |
|
122 ``Since we can't use \code{var}s I was wondering if we could use a stack?'' |
|
123 \bigskip\bigskip\bigskip\bigskip |
|
124 |
|
125 \small |
|
126 My \pcode{collatz} and \pcode{collatz_max} functions are 4 loc each. |
|
127 \end{frame} |
|
128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
129 |
|
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
131 \begin{frame}[t] |
|
132 \frametitle{Email: Hate 'val'} |
|
133 |
|
134 \mbox{}\\[-22mm]\mbox{} |
|
135 |
|
136 \begin{center} |
|
137 \begin{bubble}[10.5cm] |
|
138 Subject: \textbf{Hate '\textbf{\texttt{val}}'}\hfill 01:00 AM\medskip\\ |
|
139 |
|
140 Hello Mr Urban,\medskip\\ |
|
141 |
|
142 I just wanted to ask, how are we suppose to work |
|
143 with the completely useless \textbf{\texttt{val}}, that can’t be changed ever? Why is |
|
144 this rule active at all? I’ve spent 4 hours not thinking on the |
|
145 coursework, but how to bypass this annoying rule. What’s the whole |
|
146 point of all these coursework, when we can’t use everything Scala |
|
147 gives us?!?\medskip\\ |
|
148 |
|
149 Regards.\\ |
|
150 \mbox{}\hspace{5mm}\textcolor{black!50}{<<deleted>>}\\ |
|
151 \end{bubble} |
|
152 \end{center} |
|
153 |
|
154 \end{frame} |
|
155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
156 |
|
157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
158 \begin{frame}[c] |
|
159 |
|
160 \mbox{}\\[-25mm]\mbox{} |
|
161 |
|
162 \begin{center} |
|
163 \begin{bubble}[10.5cm] |
|
164 Subject: \textbf{Re: Hate '\textbf{\texttt{val}}'}\hfill 01:02 AM\bigskip\bigskip\\ |
|
165 |
|
166 \textcolor{black!70}{ |
|
167 \textit{\large<<my usual rant about fp\ldots\\ concurrency bla bla\ldots{} better programs |
|
168 yada>>}}\bigskip\bigskip\bigskip |
|
169 |
|
170 PS: What are you trying to do where you desperately want to use \texttt{var}? |
|
171 \end{bubble} |
|
172 \end{center} |
|
173 |
|
174 \end{frame} |
|
175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
176 |
|
177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
178 \begin{frame}[c,fragile] |
|
179 |
|
180 \begin{textblock}{6}(0.5,0.5) |
|
181 \begin{bubble}[11.5cm] |
|
182 \small |
|
183 Subject: \textbf{Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:04 AM\medskip\\ |
|
184 |
|
185 \textbf{Right now my is\_legal function works fine:} |
|
186 |
|
187 \footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm] |
|
188 def is_legal(dim: Int, path: Path)(x: Pos): Boolean = { |
|
189 var boolReturn = false |
|
190 if(x._1 > dim || x._2 > dim || x._1 < 0 || x._2 < 0) { |
|
191 else { var breakLoop = false |
|
192 if(path == Nil) { boolReturn = true } |
|
193 else { for(i <- 0 until path.length) { |
|
194 if(breakLoop == false) { |
|
195 if(path(i) == x) { |
|
196 boolReturn = true |
|
197 breakLoop = true |
|
198 } |
|
199 else { boolReturn = false } |
|
200 } else breakLoop |
|
201 } |
|
202 } |
|
203 boolReturn |
|
204 } |
|
205 \end{lstlisting} |
|
206 \end{bubble} |
|
207 \end{textblock} |
|
208 |
|
209 \begin{textblock}{6}(8.2,11.8) |
|
210 \begin{bubble}[5.5cm]\footnotesize\bf |
|
211 \ldots{}but I can’t make it work with boolReturn being val. What approach would |
|
212 you recommend in this case, and is using var in this case justified? |
|
213 \end{bubble} |
|
214 \end{textblock} |
|
215 |
|
216 \only<2>{ |
|
217 \begin{textblock}{6}(0.3,11.8) |
|
218 \begin{bubble}[3.1cm] |
|
219 \textbf{Me:} |
|
220 \raisebox{-12mm}{\includegraphics[scale=0.08]{../pics/throwup.jpg}} |
|
221 \end{bubble} |
|
222 \end{textblock}} |
|
223 |
|
224 \end{frame} |
|
225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
226 |
|
227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
228 \begin{frame}[t,fragile] |
|
229 |
|
230 \mbox{}\\[-25mm]\mbox{} |
|
231 |
|
232 \begin{textblock}{6}(0.5,2) |
|
233 \begin{bubble}[11.5cm] |
|
234 Subject: \textbf{Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:06 AM\bigskip\\ |
|
235 \small |
|
236 |
|
237 OK. So you want to make sure that the \texttt{x}-position is not outside the |
|
238 board....and furthermore you want to make sure that the \texttt{x}-position |
|
239 is not yet in the path list. How about something like\bigskip |
|
240 |
|
241 \footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm] |
|
242 def is_legal(dim: Int, path: Path)(x: Pos): Boolean = |
|
243 ...<<some board conditions>>... && !path.contains(x) |
|
244 \end{lstlisting}\bigskip |
|
245 |
|
246 \small Does not even contain a \texttt{val}. |
|
247 \end{bubble} |
|
248 \end{textblock} |
|
249 |
|
250 \begin{textblock}{6}(7,12) |
|
251 \footnotesize\textcolor{black!50}{(This is all on one line)} |
|
252 \end{textblock} |
|
253 |
|
254 \end{frame} |
|
255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
256 |
|
257 |
|
258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
259 \begin{frame}[t,fragile] |
|
260 |
|
261 \mbox{}\\[-15mm]\mbox{} |
|
262 |
|
263 \begin{textblock}{6}(1,3) |
|
264 \begin{bubble}[10.5cm] |
|
265 Subject: \textbf{Re: Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 11:02 AM\bigskip\bigskip\\ |
|
266 |
|
267 THANK YOU! You made me change my coding perspective. Because of you, |
|
268 I figured out the next one\ldots |
|
269 \end{bubble} |
|
270 \end{textblock} |
|
271 |
|
272 \only<2>{ |
|
273 \begin{textblock}{6}(0.3,11.8) |
|
274 \begin{bubble}[3.1cm] |
|
275 \textbf{Me:} |
|
276 \raisebox{-12mm}{\includegraphics[scale=0.15]{../pics/happy.jpg}} |
|
277 \end{bubble} |
|
278 \end{textblock}} |
|
279 |
|
280 \end{frame} |
|
281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
282 |
|
283 |
|
284 |
|
285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
286 \begin{frame}[c] |
|
287 \frametitle{Assignments} |
|
288 |
|
289 Don't change any names or types in the templates!\bigskip |
|
290 |
|
291 Avoid at all costs: |
|
292 |
|
293 \begin{itemize} |
|
294 \item \code{var} |
|
295 \item \code{return} |
|
296 \item \texttt{ListBuffer} |
|
297 \item \texttt{mutable} |
|
298 \item \texttt{.par} |
|
299 \end{itemize}\bigskip\bigskip |
|
300 |
|
301 I cannot think of a good reason to use stacks. |
|
302 \end{frame} |
|
303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
304 |
|
305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
306 \begin{frame}[t] |
|
307 \frametitle{For-Comprehensions Again} |
|
308 |
85 |
309 \begin{center} |
86 \begin{center} |
310 \begin{tikzpicture}[scale=1, |
87 \begin{tikzpicture}[scale=1, |
311 node/.style={ |
88 node/.style={ |
312 rectangle,rounded corners=3mm, |
89 rectangle,rounded corners=3mm, |