slides/slides02.tex
author Christian Urban <urbanc@in.tum.de>
Sun, 16 Dec 2018 21:43:14 +0000
changeset 249 1997cfcd6334
parent 205 940e70378d90
child 316 8b57dd326a91
permissions -rw-r--r--
updated

\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)\\
    Slides \& Code: & KEATS\medskip\\
    Office Hours: &  Mondays 12:00 -- 14:00\\
  \end{tabular}
  \end{center}


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


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
\begin{frame}[c,fragile]
\frametitle{Scala on Lab Computers}

\begin{lstlisting}[language={},numbers=none,
  basicstyle=\ttfamily\small,xleftmargin=-2mm]
$ /usr/share/scala/bin/scala
  
Welcome to Scala 2.12.6 (Java HotSpot(TM) 64-Bit
Server VM, Java 10.0.1). Type in expressions for
evaluation. Or try :help.

scala>
\end{lstlisting}%$

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

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

Don't change anything with the templates!\bigskip

Avoid at all costs:

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


\mbox{}\hfill\textit{``Scala --- \underline{S}lowly \underline{c}ompiled 
\underline{a}cademic \underline{la}nguage''}\smallskip\\
\mbox{}\hfill\textit{ --- a joke(?) found on Twitter}\bigskip
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]
\frametitle{Email: Hate 'val'}

\mbox{}\\[-25mm]\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}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\firstcircle{(0,0) circle (1.4cm)}
\def\secondcircle{(0:2cm) circle (1.4cm)}
\colorlet{circle edge}{blue!50}
\colorlet{circle area}{blue!20}

\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
    outline/.style={draw=circle edge, thick}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c,fragile]
\frametitle{Par: Intersections}

\begin{textblock}{6}(1,2)
\begin{tikzpicture}
  \draw[outline] \firstcircle node {$A$};
  \node[anchor=south] at (current bounding box.north)
    {$A = \{1,2,3,\ldots,1000\}$};
\end{tikzpicture}
\end{textblock}

\begin{textblock}{6}(8,2)
\begin{tikzpicture}
  \draw[outline] \secondcircle node {$B$};
  \node[anchor=south] at (current bounding box.north)
    {$B = \{1,5,9,13,\ldots,997\}$};
\end{tikzpicture}
\end{textblock}

\begin{textblock}{6}(3.3,9)
\begin{tikzpicture}
    \begin{scope}
        \clip \firstcircle;
        \fill[filled] \secondcircle;
    \end{scope}
    \draw[outline] \firstcircle node {$A$};
    \draw[outline] \secondcircle node {$B$};
    \node[anchor=north] at (current bounding box.south)
    {How many elements are in $A \cap B$?};
\end{tikzpicture}
\end{textblock}  

\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{Why Scala? No null!}


\begin{itemize}
\item \large {\bf You can avoid \textcolor{blue}{\texttt{null}}}:
\end{itemize}


\begin{textblock}{6}(1,5)
  \begin{bubble}[10.5cm]\small
      ``I call it my billion-dollar mistake. It was the invention of
      the null reference in 1965. At that time, I was designing the
      first comprehensive type system for references in an object
      oriented language (ALGOL W). My goal was to ensure that all use
      of references should be absolutely safe, with checking performed
      automatically by the compiler. But I couldn't resist the
      temptation to put in a null reference, simply because it was so
      easy to implement. This has led to innumerable errors,
      vulnerabilities, and system crashes, which have probably caused
      a billion dollars of pain and damage in the last forty years.''
      \hfill Sir Tony (Hoare)
\end{bubble}
\end{textblock}
  
\begin{textblock}{5}(12.5,1.9)
\includegraphics[scale=0.05]{../pics/hoare.jpg}\\
\end{textblock}
  
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


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

%\begin{center}
%\chessboard[maxfield=g7,
%            color=blue!50,
%            linewidth=0.2em,
%            shortenstart=0.5ex,
%            shortenend=0.5ex,
%            markstyle=cross,
%            markfields={a4, c4, Z3, d3, Z1, d1, a0, c0},
%            color=red!50,
%            markfields={f5, e6},
%            boardfontsize=12pt,labelfontsize=8pt,
%            setpieces={Ng7, Nb2},showmover=false]
%\end{center}
            
\begin{center}
My Office Hours: Mondays 12 -- 14
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
\end{document}


\end{document}

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