

% add the PATH to retrieve cls and sty beamer styles files
\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{../../support/beamer/}\input@path}% prepend
\makeatother

% \documentclass{pharoslides}
% \documentclass[aspectratio=169]{pharoslides} % format 16/9
\documentclass[withvideo]{pharoslides} % format 16/9 + incrustation video

\graphicspath{{./figures/}{../}{../../support/beamer/imgs/}}

%Information to be included in the title page:
\title{Dynamic Vs. Literal Arrays}
\subtitle{}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{W6S08}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{What You Will Learn}

\begin{itemize}
\item Literal arrays are not created using messages
\item Dynamic arrays are created at runtime using messages
\item Still they are all instances of \code{Array}
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Remember: Literal Arrays}

Literal array definition can only contain objects that have a textual (literal) representation: numbers, strings, nil, symbols, boolean

\begin{listing}{}
#(45 'milou' 1300 true #tintin)
> #(45 'milou' 1300 true #tintin)
\end{listing}

Literal arrays are instances of the class \code{Array}

\begin{listing}{}
#(45 38 1300 8) class
> Array
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Literal/Dynamic Arrays}

A literal array

\begin{listing}{}
#(45 38 'milou' 8) 
> #(45 38 'milou' 8) 
\end{listing}

A dynamic array

\begin{listing}{}
Array with: 45 with: 38 with: 'milou' with: 8
> #(45 38 'milou' 8) 
\end{listing}

Both are \code{Array} instances
\end{frame}



\begin{frame}[fragile]

\frametitle{Dynamic Array Compact Syntax}

Defining dynamic arrays is tedious 

\begin{listing}{}
| array | 
array := (Array new: 2). 
array 
    at: 1 put: 10 @ 10 ; 
    at: 2 put: (Point x: 100 y: 200).
array
\end{listing}

\code{\{ expression1 . expression2 \}} is syntactic sugar to create dynamic arrays

\begin{listing}{}
{(10@20) . (100@200)}
{Point x: 10 y: 20 . Point x: 100 y: 200}
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Literal Array Creation Time}

Literal arrays are created at \textbf{compile time} by the parser when the expression is read  and not during the execution

\begin{listing}{}
| a |
a := 12.
#(a + 1 . 13) 
> #(#a #+ 1 #'.' 13)
\end{listing}

Dynamic arrays execute expressions 

\begin{listing}{}
| a |
a := 12.
{a + 1 . 13} 
> #(13 . 13)
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{ Literal vs. Dynamic}

\code{\{\}} executes expressions while \code{\#()} not

\begin{listing}{}
{(10@20) . (10@20)}
> {(10@20) . (10@20)}

#((10@20) . (10@20))
> #(#(10 #@ 20) #'.' #(10 #@ 20))
\end{listing}

\begin{listing}{}
{(10@20) . (10@20)} size 
> 2

#((10@20) . (10@20)) size 
> 3
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Nested Arrays}

\code{()} inside a literal array produces a nested literal array

\begin{listing}{}
#((10@20) (100@200))
> #(#(10 #@ 20) #(100 #@ 200))
\end{listing}

\begin{listing}{}
#((10@20) . (100@200)) first
> #(10 #@ 20)
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Summary}

\begin{itemize}
\item Only one kind of Arrays
\item Three ways
\begin{itemize}
\item Literal syntax: \code{\#( )} (no message)
\item Using messages \code{Array new: 3} 
\item Syntactic sugar: Dynamic \code{\{ . . \} } 
\end{itemize}

\end{itemize}
\end{frame}




% \setlength{\textwidth}{\originaltextwidth}
\setbeamertemplate{background canvas}{\insertBorderForHandout}

\begin{frame}[plain]

\begin{minipage}{\originaltextwidth}
\centering
\large


\vspace{2em}

A course by

\vspace{1em}

\hspace{-20px}\includegraphics[height=32px]{inriaLogo}\hspace{3em}\raisebox{7px}{and}\hspace{3em}\raisebox{-6px}{\includegraphics[height=30px]{logoutop}}

\vspace{2em}

in collaboration with

\vspace{1em}

\includegraphics[height=40px]{unisciellogo}\hskip 1.5em%
\raisebox{5px}{\includegraphics[height=30px]{unitlogo}}\hskip 2em%
\raisebox{8px}{\includegraphics[height=24px]{univLilleLogo}}\hskip 2em%
\raisebox{3px}{\includegraphics[height=29px]{logo-IMT}}\hskip 2em%
\raisebox{1px}{\includegraphics[height=32px]{minesDouaiLogo}}

\vspace{2.5em}

\includegraphics[width=50px]{by-nc-nd} \tiny \hskip 0.5em \raisebox{5px}{Inria 2016}

\medskip

\tiny
Except where otherwise noted, this work is licensed under CC BY-NC-ND 3.0 France

\url{https://creativecommons.org/licenses/by-nc-nd/3.0/fr/} 

\end{minipage}
\end{frame}

\end{document}

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