

% 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{Characters, Strings and Symbols}
\subtitle{}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{W6S07}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{What You Will Learn}

\begin{itemize}
\item Characters
\item Strings: a collection of characters
\item Symbols: unique strings
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Characters}

\begin{itemize}
\item Characters:
\begin{itemize}
\item \code{\$F}, \code{\$Q} \code{\$U} \code{\$E} \code{\$N} \code{\$T} \code{\$i} \code{\$N}
\end{itemize}

\item Unprintable characters:
\begin{itemize}
\item \code{Character space}, \code{Character tab}, \code{Character cr}
\end{itemize}

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{'Strings'}

Delimited by \code{'}

\begin{listing}{}
'eclair au chocolat'	
\end{listing}

\begin{listing}{}
'eclair au chocolat' size
> 18
\end{listing}

 

\begin{listing}{}
Character space split: 'eclair au chocolat' 
> an OrderedCollection('eclair' 'au' 'chocolat')	
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{A String: a Collection of Characters}

\begin{listing}{}
'eclair au chocolat' at: 1
> $e
\end{listing}

\begin{listing}{}
'eclair au chocolat' do: [:each | Transcript show: each ; cr ]
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Quote in Strings}

\begin{itemize}
\item To add a quote in a string with just type it twice
\end{itemize}

\begin{listing}{}
'L''eclair au chocolat' 
\end{listing}

\begin{itemize}
\item Pay attention there is only one element 
\end{itemize}

\begin{listing}{}
'L''eclair au chocolat' at: 2
> $'

'L''eclair au chocolat' at: 3
> $e
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Getting the Last Char}

\begin{listing}{}
| str |
str := 'Tiramisu'.
str at: str size
> $u

str last
> $u
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Ways to Obtain a String}

\begin{listing}{}
#mac asString
> 'mac'
\end{listing}

\begin{listing}{}
12 printString
>'12'
\end{listing}

\begin{listing}{}
String with: $A
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{For Concatenation Use ,}

\begin{listing}{}
'Calvin' , ' & ', 'Hobbes'
> 'Calvin & Hobbes'
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{ Take Care With ,}

Message comma \code{\#,} copies strings so multiple concatenations can generate useless intermediate versions

\begin{listing}{}
'Calvin' , ' & ', 'Hobbes'
> 'Calvin & Hobbes'
\end{listing}

\begin{itemize}
\item Benchmark it
\item If this is worth, use a stream to avoid creating multiple intermediary strings
\end{itemize}

\begin{listing}{}
String streamContents: [ :s |
   s 
     nextPutAll: 'Calvin';
     nextPutAll: ' & ';
     nextPutAll: 'Hobbes' ]
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Symbols}

\begin{itemize}
\item \code{\#calvin} is a symbol
\item A kind of string
\item Unique in the system
\item Starts with \code{\#}
\begin{itemize}
\item \code{\#class} \code{\#mac} \code{\#at:put:} \code{\#+} \code{\#accept:}
\end{itemize}

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Symbols are Unique}

Two  symbols with the same representation points to the same object 
 

\begin{listing}{}
#calvin == #calvin
> true 
\end{listing}

Two strings with the same representation may be different objects depending on compiler optimisations
\end{frame}



\begin{frame}[fragile]

\frametitle{Symbols vs. Strings}

\begin{itemize}
\item A symbol is a read-only and unique object 
\item A string is a mutable object (for now)
\item Symbols are used as method selectors
\item Symbols are good candidates for identity based dictionaries (\code{IdentityDictionary})
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{What You Should Know}

\begin{itemize}
\item Strings are collections of characters
\item Symbols are unique immutable strings
\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:
