33 \end{tabular}} |
83 \end{tabular}} |
34 |
84 |
35 \normalsize |
85 \normalsize |
36 \begin{center} |
86 \begin{center} |
37 \begin{tabular}{ll} |
87 \begin{tabular}{ll} |
38 Email: & christian.urban at kcl.ac.uk\\ |
88 Email: & christian.urban at kcl.ac.uk\\ |
39 Office: & S1.27 (1st floor Strand Building)\\ |
89 Office: & N7.07 (North Wing, Bush House)\\ |
40 Slides \& Code: & KEATS |
90 Slides \& Code: & KEATS\medskip\\ |
|
91 Scala Office & \\ |
|
92 Hours: & Thursdays 11 -- 13\\ |
41 \end{tabular} |
93 \end{tabular} |
42 \end{center} |
94 \end{center} |
43 |
95 |
44 |
96 |
45 \end{frame} |
97 \end{frame} |
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
47 |
99 |
48 \begin{frame}[c, fragile] |
|
49 \frametitle{The Joy of Immutability} |
|
50 |
|
51 \begin{itemize} |
|
52 \item If you need to manipulate some data in a list say, then you make |
|
53 a new list with the updated values, rather than revise the original |
|
54 list. Easy!\medskip |
|
55 |
|
56 {\small |
|
57 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm] |
|
58 val old_list = List(1, 2, 3, 5) |
|
59 val new_list = 0 :: old_list |
|
60 \end{lstlisting}} |
|
61 |
|
62 \item You do not have to be defensive about who can access the data |
|
63 (concurrency, lazyness). |
|
64 \end{itemize} |
|
65 \end{frame} |
|
66 |
|
67 |
|
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
69 \begin{frame}[t] |
|
70 \frametitle{Email: Hate 'val'} |
|
71 |
|
72 \mbox{}\\[-25mm]\mbox{} |
|
73 |
|
74 \begin{center} |
|
75 \begin{bubble}[10.5cm] |
|
76 Subject: \textbf{Hate '\textbf{\texttt{val}}'}\hfill 01:00 AM\medskip\\ |
|
77 |
|
78 Hello Mr Urban,\medskip\\ |
|
79 |
|
80 I just wanted to ask, how are we suppose to work |
|
81 with the completely useless \textbf{\texttt{val}}, that can’t be changed ever? Why is |
|
82 this rule active at all? I’ve spent 4 hours not thinking on the |
|
83 coursework, but how to bypass this annoying rule. What’s the whole |
|
84 point of all these coursework, when we can’t use everything Scala |
|
85 gives us?!?\medskip\\ |
|
86 |
|
87 Regards.\\ |
|
88 \mbox{}\hspace{5mm}\textcolor{black!50}{<<deleted>>}\\ |
|
89 \end{bubble} |
|
90 \end{center} |
|
91 |
|
92 \end{frame} |
|
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
94 |
|
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
96 \begin{frame}[c] |
|
97 |
|
98 \mbox{}\\[-25mm]\mbox{} |
|
99 |
|
100 \begin{center} |
|
101 \begin{bubble}[10.5cm] |
|
102 Subject: \textbf{Re: Hate '\textbf{\texttt{val}}'}\hfill 01:02 AM\bigskip\bigskip\\ |
|
103 |
|
104 \textcolor{black!70}{ |
|
105 \textit{\large<<my usual rant about fp\ldots\\ concurrency bla bla\ldots{} better programs |
|
106 yada>>}}\bigskip\bigskip\bigskip |
|
107 |
|
108 PS: What are you trying to do where you desperately want to use \texttt{var}? |
|
109 \end{bubble} |
|
110 \end{center} |
|
111 |
|
112 \end{frame} |
|
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
114 |
100 |
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
116 \begin{frame}[c,fragile] |
102 \begin{frame}[c,fragile] |
117 |
103 |
118 \begin{textblock}{6}(0.5,0.5) |
104 \begin{textblock}{6}(0.5,0.5) |
119 \begin{bubble}[11.5cm] |
105 \begin{bubble}[11.5cm] |
120 \small |
106 \footnotesize |
121 Subject: \textbf{Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:04 AM\medskip\\ |
107 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm] |
122 |
108 import java.util.concurrent._ |
123 \textbf{Right now my is\_legal function works fine:} |
109 import java.util.concurrent.atomic._ |
124 |
110 |
125 \footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm] |
111 def collatz(input:Int){ |
126 def is_legal(dim: Int, path: Path)(x: Pos): Boolean = { |
112 CollatzConjecture(input); |
127 var boolReturn = false |
113 println(count.get()); |
128 if(x._1 > dim || x._2 > dim || x._1 < 0 || x._2 < 0) { |
114 } |
129 else { var breakLoop = false |
115 def collatz_max(input:Int){ |
130 if(path == Nil) { boolReturn = true } |
116 val List = new Array[Int](input) |
131 else { for(i <- 0 until path.length) { |
117 for (i <- 0 to input-1){ |
132 if(breakLoop == false) { |
118 CollaĵConjecture(i); |
133 if(path(i) == x) { |
119 List(i)=count.get(); |
134 boolReturn = true |
120 count.set(0); |
135 breakLoop = true |
|
136 } |
|
137 else { boolReturn = false } |
|
138 } else breakLoop |
|
139 } |
121 } |
140 } |
122 val max = new AtomicInteger(); |
141 boolReturn |
123 max.set(List(0)); |
142 } |
124 val index = new AtomicInteger(); |
|
125 index.set(1); |
|
126 |
143 \end{lstlisting} |
127 \end{lstlisting} |
144 \end{bubble} |
128 \end{bubble} |
145 \end{textblock} |
129 \end{textblock} |
146 |
130 |
147 \begin{textblock}{6}(8.2,11.8) |
131 \end{frame} |
148 \begin{bubble}[5.5cm]\footnotesize\bf |
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
149 \ldots{}but I can’t make it work with boolReturn being val. What approach would |
133 |
150 you recommend in this case, and is using var in this case justified? |
134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
135 \begin{frame}[c,fragile] |
|
136 |
|
137 \begin{textblock}{6}(0.5,0.5) |
|
138 \begin{bubble}[11.5cm] |
|
139 \footnotesize |
|
140 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm] |
|
141 for(i<-0 to input-1){ |
|
142 val temp :Int=max.get(); |
|
143 if (temp < List(i)){ |
|
144 max.set(List(i)); |
|
145 index.set(i); |
|
146 } |
|
147 } |
|
148 println("("+max.get() +","+ index.get()+ ")"); |
|
149 } |
|
150 |
|
151 def CollatzConjecture(n: Long): Long = { |
|
152 count.incrementAndGet(); |
|
153 if (n <= 1) |
|
154 1 |
|
155 else if (n\%2 ==0) |
|
156 CollatzConjecture(n/2); |
|
157 else |
|
158 CollatzConjecture((3*n)+1); |
|
159 } |
|
160 } |
|
161 \end{lstlisting} |
151 \end{bubble} |
162 \end{bubble} |
152 \end{textblock} |
163 \end{textblock} |
153 |
164 |
154 \only<2>{ |
|
155 \begin{textblock}{6}(0.3,11.8) |
|
156 \begin{bubble}[3.1cm] |
|
157 \textbf{Me:} \includegraphics[scale=0.08, valign=t]{../pics/throwup.jpg} |
|
158 \end{bubble} |
|
159 \end{textblock}} |
|
160 |
|
161 \end{frame} |
165 \end{frame} |
162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
166 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
163 |
167 |
164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
165 \begin{frame}[t,fragile] |
|
166 |
|
167 \mbox{}\\[-25mm]\mbox{} |
|
168 |
|
169 \begin{textblock}{6}(0.5,2) |
|
170 \begin{bubble}[11.5cm] |
|
171 Subject: \textbf{Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:06 AM\bigskip\\ |
|
172 \small |
|
173 |
|
174 OK. So you want to make sure that the \texttt{x}-position is not outside the |
|
175 board....and furthermore you want to make sure that the \texttt{x}-position |
|
176 is not yet in the path list. How about something like\bigskip |
|
177 |
|
178 \footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm] |
|
179 def is_legal(dim: Int, path: Path)(x: Pos): Boolean = |
|
180 ...<<some board conditions>>... && !path.contains(x) |
|
181 \end{lstlisting}\bigskip |
|
182 |
|
183 \small Does not even contain a \texttt{val}. |
|
184 \end{bubble} |
|
185 \end{textblock} |
|
186 |
|
187 \begin{textblock}{6}(7,12) |
|
188 \footnotesize\textcolor{black!50}{(This is all on one line)} |
|
189 \end{textblock} |
|
190 |
|
191 \end{frame} |
|
192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
193 |
|
194 |
|
195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
196 \begin{frame}[t,fragile] |
|
197 |
|
198 \mbox{}\\[-15mm]\mbox{} |
|
199 |
|
200 \begin{textblock}{6}(1,3) |
|
201 \begin{bubble}[10.5cm] |
|
202 Subject: \textbf{Re: Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 11:02 AM\bigskip\bigskip\\ |
|
203 |
|
204 THANK YOU! You made me change my coding perspective. Because of you, |
|
205 I figured out the next one\ldots |
|
206 \end{bubble} |
|
207 \end{textblock} |
|
208 |
|
209 \only<2>{ |
|
210 \begin{textblock}{6}(0.3,11.8) |
|
211 \begin{bubble}[3.1cm] |
|
212 \textbf{Me:} \includegraphics[scale=0.08]{../pics/happy.jpg} |
|
213 \end{bubble} |
|
214 \end{textblock}} |
|
215 |
|
216 \end{frame} |
|
217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
218 |
168 |
219 |
169 |
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
221 \begin{frame}[c] |
171 \begin{frame}[c] |
222 \frametitle{CW3: Regexes (1 Part)} |
172 \frametitle{CW3 (1 Part): Regexes} |
223 |
173 |
224 \begin{center} |
174 \begin{center} |
225 Graphs: $(a^*)^* b$ and strings $\underbrace{\;a\ldots a\;}_{n}$\bigskip |
175 Graphs: $(a^*)^* b$ and strings $\underbrace{\;a\ldots a\;}_{n}$\bigskip |
226 |
176 |
227 \begin{tabular}[t]{@{\hspace{-8mm}}c@{\hspace{-4mm}}c@{}} |
177 \begin{tabular}[t]{@{\hspace{-8mm}}c@{\hspace{-4mm}}c@{}} |
285 |
235 |
286 |
236 |
287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
288 |
238 |
289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
240 \begin{frame}[c,fragile] |
|
241 \frametitle{\alert{Questions?}} |
|
242 |
|
243 {\tiny |
|
244 \begin{verbatim} |
|
245 * |
|
246 * * |
|
247 * * |
|
248 * * * * |
|
249 * * |
|
250 * * * * |
|
251 * * * * |
|
252 * * * * * * * * |
|
253 * * |
|
254 * * * * |
|
255 * * * * |
|
256 * * * * * * * * |
|
257 * * * * |
|
258 * * * * * * * * |
|
259 * * * * * * * * |
|
260 * * * * * * * * * * * * * * * * |
|
261 * * |
|
262 * * * * |
|
263 * * * * |
|
264 * * * * * * * * |
|
265 * * * * |
|
266 * * * * * * * * |
|
267 * * * * * * * * |
|
268 * * * * * * * * * * * * * * * * |
|
269 * * * * |
|
270 * * * * * * * * |
|
271 * * * * * * * * |
|
272 * * * * * * * * * * * * * * * * |
|
273 * * * * * * * * |
|
274 * * * * * * * * * * * * * * * * |
|
275 * * * * * * * * * * * * * * * * |
|
276 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
277 \end{verbatim}} |
|
278 |
|
279 |
|
280 \begin{textblock}{6}(8.5,3.5) |
|
281 \begin{bubble}[5cm] |
|
282 \footnotesize |
|
283 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm] |
|
284 ++++++++[>+>++++<<-]>++>> |
|
285 +<[-[>>+<<-]+>>]>+[-<<<[- |
|
286 >[+[-]+>++>>>-<<]<[<]>>++ |
|
287 ++++[<<+++++>>-]+<<++.[-] |
|
288 <<]>.>+[>>]>+] |
|
289 \end{lstlisting} |
|
290 \end{bubble} |
|
291 \end{textblock} |
|
292 |
|
293 \end{frame} |
|
294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
295 |
|
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
297 |
290 \begin{frame}[c] |
298 \begin{frame}[c] |
291 \frametitle{\begin{tabular}{c}\\[3cm]\alert{Questions?}\end{tabular}} |
299 \frametitle{Marks for CW6 (Part 1 + 2)} |
292 |
300 |
293 \mbox{}\footnotesize |
301 Raw marks: |
294 Thanks: ``\it{}By the way - Scala is really getting quite fun |
|
295 when you start to get the hang of it\ldots'' |
|
296 |
|
297 \end{frame} |
|
298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
299 |
|
300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
301 |
|
302 \begin{frame}[c] |
|
303 \frametitle{Marks for CW6 (Part 1)} |
|
304 |
|
305 Absolute raw marks, alleged collusions still included: |
|
306 |
302 |
307 \begin{itemize} |
303 \begin{itemize} |
308 \item 0\%: 18 students |
304 \item 0\%: 21 students |
309 \item 1\%: 2 |
305 \item 1\%: 1 |
310 \item 2\%: 11 |
306 \item 2\%: 2 |
311 \item 3\%: 29 |
307 \item 3\%: 13 |
312 \item 4\%: 18 |
308 \item 4\%: 18 |
313 \item 5\%: 33 |
309 \item 5\%: 66 |
314 \item 6\%: 55 |
310 \item 6\%: 154 |
315 \item 7\%: 62 |
|
316 \end{itemize} |
311 \end{itemize} |
317 \end{frame} |
312 \end{frame} |
318 |
313 |
319 |
314 |
320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |