slides/slides02.tex
author Christian Urban <urbanc@in.tum.de>
Mon, 11 Nov 2019 14:04:22 +0000
changeset 317 607ceabeeffc
parent 316 8b57dd326a91
child 318 029e2862bb4e
permissions -rw-r--r--
updated

% !TEX program = xelatex
\documentclass[dvipsnames,14pt,t,xelatex]{beamer}
\usepackage{chessboard}
\usepackage[LSBC4,T1]{fontenc}
\usepackage{../slides}
\usepackage{../graphics}
\usepackage{../langs}

% \usepackage{../data}

\hfuzz=220pt 

%\setmonofont[Scale=.88]{Consolas}
%\newfontfamily{\consolas}{Consolas}

\lstset{language=Scala,
        style=mystyle,
        numbersep=0pt,
        numbers=none,
        xleftmargin=0mm}

\newcommand{\bl}[1]{\textcolor{blue}{#1}}     

% beamer stuff 
\renewcommand{\slidecaption}{PEP (Scala) 02, King's College London}


\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]
\frametitle{%
  \begin{tabular}{@ {}c@ {}}
  \\[5mm]
  \huge PEP Scala (2) 
  \end{tabular}}

  \normalsize
  \begin{center}
  \begin{tabular}{ll}
    Email:  & christian.urban at kcl.ac.uk\\
    Office: & N\liningnums{7.07} (North Wing, Bush House)\bigskip\\
    Slides \& Code: & KEATS\bigskip\\
    Office Hours: &  Thursdays 12:00 -- 14:00\\
    Additionally: & (for Scala) Tuesdays 10:45 -- 11:45\\ 
  \end{tabular}
  \end{center}


\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
\begin{frame}[c,fragile]
  \frametitle{My Scala Version}
  
  \begin{lstlisting}[language={},numbers=none,
    basicstyle=\ttfamily\small,xleftmargin=-2mm]
  $ scala
    
  Welcome to Scala 2.13.1 (Java HotSpot(TM) 
  64-Bit Server VM, Java 9). Type in expressions 
  for evaluation. Or try :help.
  
  scala>
  \end{lstlisting}%$
  \bigskip\bigskip
  
  With older versions you will get strange results with my reference implementation.
  
  \end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
\begin{frame}[c,fragile]
\frametitle{Reference Implementation}
  
Keep your implementation and my reference implementation separate.\bigskip

  \begin{lstlisting}[language={},numbers=none,
    basicstyle=\ttfamily\small,xleftmargin=-2mm]
  $ scala -cp collatz.jar
  
  scala> CW6a.collatz(6)
  res0: Long = 8


  scala> import CW6a._
  scala> collatz(9)
  res1: Long = 19
  \end{lstlisting}%$

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
\begin{frame}[t]
  \frametitle{Preliminary Part 7}
  
  \Large
  \[
    \texttt{overlap}(d_1, d_2) = \frac{d_1 \cdot d_2}{max(d_1^2, d_2^2)}  
  \]\bigskip

  \large
  \quad{}\;where \;$d_1^2$\; means \;$d_1 \cdot d_1$\; and so on
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
\begin{frame}[c]
  \frametitle{Discussion Forum}
  
  \large
  ``Since we cant use \code{var}s I was wondering if we could use a stack?''
  \bigskip\bigskip\bigskip\bigskip

  \small
  My \pcode{collatz} and \pcode{collatz_max} functions are 4 loc each. 
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]
  \frametitle{Email: Hate 'val'}
  
  \mbox{}\\[-22mm]\mbox{}
  
  \begin{center}
    \begin{bubble}[10.5cm]
    Subject: \textbf{Hate '\textbf{\texttt{val}}'}\hfill 01:00 AM\medskip\\
  
    Hello Mr Urban,\medskip\\
  
    I just wanted to ask, how are we suppose to work
    with the completely useless \textbf{\texttt{val}}, that can’t be changed ever? Why is
    this rule active at all? I’ve spent 4 hours not thinking on the
    coursework, but how to bypass this annoying rule. What’s the whole
    point of all these coursework, when we can’t use everything Scala
    gives us?!?\medskip\\
  
    Regards.\\
    \mbox{}\hspace{5mm}\textcolor{black!50}{<<deleted>>}\\
    \end{bubble}
  \end{center}
  
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]

 \mbox{}\\[-25mm]\mbox{}

\begin{center}
  \begin{bubble}[10.5cm]
  Subject: \textbf{Re: Hate '\textbf{\texttt{val}}'}\hfill 01:02 AM\bigskip\bigskip\\

  \textcolor{black!70}{
    \textit{\large<<my usual rant about fp\ldots\\ concurrency bla bla\ldots{} better programs
    yada>>}}\bigskip\bigskip\bigskip
  
  PS: What are you trying to do where you desperately want to use \texttt{var}?
  \end{bubble}
\end{center}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c,fragile]

\begin{textblock}{6}(0.5,0.5)
\begin{bubble}[11.5cm]
  \small  
  Subject: \textbf{Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:04 AM\medskip\\

  \textbf{Right now my is\_legal function works fine:}
  
\footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
 def is_legal(dim: Int, path: Path)(x: Pos): Boolean = {
   var boolReturn = false
   if(x._1 > dim || x._2 > dim || x._1 < 0 || x._2 < 0) {
   else { var breakLoop = false
          if(path == Nil) { boolReturn = true }
          else { for(i <- 0 until path.length) {
                    if(breakLoop == false) {
                      if(path(i) == x) {
                        boolReturn = true
                        breakLoop = true
                      }
                      else { boolReturn = false }
                    } else breakLoop
            }
          }
          boolReturn
   }
\end{lstlisting}
\end{bubble}
\end{textblock}

\begin{textblock}{6}(8.2,11.8)
\begin{bubble}[5.5cm]\footnotesize\bf
\ldots{}but I can’t make it work with boolReturn being val. What approach would
you recommend in this case, and is using var in this case justified?
\end{bubble}
\end{textblock}

\only<2>{
\begin{textblock}{6}(0.3,11.8)
  \begin{bubble}[3.1cm]
    \textbf{Me:}
    \raisebox{-12mm}{\includegraphics[scale=0.08]{../pics/throwup.jpg}}
  \end{bubble}
\end{textblock}}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t,fragile]

\mbox{}\\[-25mm]\mbox{}

\begin{textblock}{6}(0.5,2)
  \begin{bubble}[11.5cm]
  Subject: \textbf{Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:06 AM\bigskip\\
  \small
  
  OK. So you want to make sure that the \texttt{x}-position is not outside the
  board....and furthermore you want to make sure that the \texttt{x}-position
  is not yet in the path list. How about something like\bigskip

\footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
 def is_legal(dim: Int, path: Path)(x: Pos): Boolean = 
   ...<<some board conditions>>... && !path.contains(x)
\end{lstlisting}\bigskip
  
  \small Does not even contain a \texttt{val}.
  \end{bubble}
\end{textblock}

\begin{textblock}{6}(7,12)
\footnotesize\textcolor{black!50}{(This is all on one line)}
\end{textblock}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t,fragile]

\mbox{}\\[-15mm]\mbox{}

\begin{textblock}{6}(1,3)
  \begin{bubble}[10.5cm]
    Subject: \textbf{Re: Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 11:02 AM\bigskip\bigskip\\
    
    THANK YOU! You made me change my coding perspective. Because of you,
    I figured out the next one\ldots
  \end{bubble}
\end{textblock}

\only<2>{
\begin{textblock}{6}(0.3,11.8)
  \begin{bubble}[3.1cm]
    \textbf{Me:}
    \raisebox{-12mm}{\includegraphics[scale=0.15]{../pics/happy.jpg}}
  \end{bubble}
\end{textblock}}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 


 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
\begin{frame}[c]
\frametitle{Assignments}

Don't change any names or types in the templates!\bigskip

Avoid at all costs:

\begin{itemize}
\item \code{var} 
\item \code{return} 
\item \texttt{ListBuffer}
\item \texttt{mutable}
\item \texttt{.par}  
\end{itemize}\bigskip\bigskip

I cannot think of a good reason to use stacks.
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
\begin{frame}[t]
\frametitle{For-Comprehensions Again}

\begin{center}
  \begin{tikzpicture}[scale=1,
                      node/.style={
                      rectangle,rounded corners=3mm,
                      very thick,draw=black!50,
                      minimum height=18mm, minimum width=20mm,
                      top color=white,bottom color=black!20}]

  \node (A0) at (0.1,0) {\texttt{\textcolor{purple}{\textbf{for}} (\alert<2->{n} <- List(}};
  \node (A1) at (2.3,0) {\texttt{\phantom{,}1,}};
  \node (A2) at (3.2,0) {\texttt{\phantom{,}2,}};
  \node (A3) at (4.1,0) {\texttt{\phantom{,}3,}};
  \node (A4) at (5.0,0) {\texttt{\phantom{,}4,}};
  \node (A5) at (5.9,0) {\texttt{\phantom{))}5))}};
  \node (A6) at (8,0) {\texttt{\textcolor{purple}{\textbf{yield}} \alert<2->{n\,*\,n}}};

  \onslide<2->{
  \node (B0) at (1.4,-3) {\texttt{List(}};
  \node (B1) at (2.3,-3) {\texttt{\phantom{,}1,}};
  \node (B2) at (3.6,-3) {\texttt{\phantom{,}4,}};
  \node (B3) at (4.9,-3) {\texttt{\phantom{,}9,}};
  \node (B4) at (6.2,-3) {\texttt{\phantom{,}16,}};
  \node (B5) at (7.5,-3) {\texttt{\phantom{,}25)}};}

  \onslide<2->{
  \draw [->,line width=1mm] (A1.south) -- (B1.north);
  \draw [->,line width=1mm] (A2.south) -- (B2.north);
  \draw [->,line width=1mm] (A3.south) -- (B3.north);
  \draw [->,line width=1mm] (A4.south) -- (B4.north);
  \draw [->,line width=1mm] (A5.south) -- (B5.north);}

  \onslide<2->{
  \node (Q1) at (-0.45,-0.1) {};
  \node (Q2) at (-0.45,-2.8) {};
  \node (Q3) at (-0.45,-2.95) {\alert<2->{\texttt{n\,*\,n:}}};
  \draw [->,red,line width=1mm] (Q1.south) -- (Q2.north);}
 \end{tikzpicture}
\end{center}

\onslide<3>{This is for when the for-comprehension\\ \textbf{yields / produces} a result.}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
\begin{frame}[t]
\frametitle{For-Comprehensions Again}

\begin{center}
  \begin{tikzpicture}[scale=1,
                      node/.style={
                      rectangle,rounded corners=3mm,
                      very thick,draw=black!50,
                      minimum height=18mm, minimum width=20mm,
                      top color=white,bottom color=black!20}]

  \node (A0) at (0,0)
    {\texttt{\textcolor{purple}{\textbf{for}} (n <- List(1, 2, 3, 4, 5))
             \textcolor{purple}{\textbf{yield}} n\,*\,n}};

  \node (A1) at (0,-1.5) {\LARGE\textbf{vs}};       
         
  \node (A2) at (0,-3)
    {\texttt{\textcolor{purple}{\textbf{for}} (n <- List(1, 2, 3, 4, 5)) println(n)}};
 \end{tikzpicture}
\end{center}\bigskip


The second version is in case the for \textbf{does not}
produce any result.

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
\begin{frame}[t]
\frametitle{Option Type}


  
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
\begin{frame}[t]
\frametitle{Higher-Order Functions}
  
  
    
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
\frametitle{\begin{tabular}{c}\\[0cm]\alert{Questions?}\end{tabular}}

\begin{center}
  \begin{tabular}[t]{@{}l@{}l@{}}
    \includegraphics[scale=0.1]{../pics/mand4.png} & \hspace{4mm}
    \raisebox{0mm}{\includegraphics[scale=0.1]{../pics/mand3.png}}      
  \end{tabular}     
\end{center}

\begin{center}
  My Office Hours: Thursdays 12 -- 14\\
  And specifically for Scala: Tuesdays 10:45 -- 11:45
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   


\end{document}

%%% Local Variables:  
%%% mode: latex
%%% TeX-master: t
%%% End: