

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

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{Booleans}

\begin{itemize}
\item \code{true} is the unique instance of class \code{True}
\item \code{false} is the unique instance of class \code{False}
\end{itemize}

In Pharo, booleans have nothing special

\begin{itemize}
\item \& \textbar{} not
\item or: and: (lazy)
\item xor:
\item ifTrue:ifFalse:
\item ifFalse:ifTrue:
\item ...
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Eager and Lazy Logical Operators}

\begin{listing}{}
   false & (1 error: 'crazy')
   -> an error
\end{listing}

\begin{itemize}
\item the argument \code{(1 error: 'crazy')} is executed because this is a non lazy operator
\end{itemize}

\begin{listing}{}
   false and: [ 1 error: 'crazy' ]
   -> false "no error!"
\end{listing}

\begin{itemize}
\item the argument \code{{[}1 error: 'crazy'{]}} is not executed because it is not necessary
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Conditionals}

In Pharo, traditional conditional (if, else, while) are messages sent to boolean or block objects
\end{frame}



\begin{frame}[fragile]

\frametitle{Yes ifTrue:ifFalse: is a message!}

\begin{listing}{}
Weather isRaining
   ifTrue: [ self takeMyUmbrella ]
   ifFalse: [ self takeMySunglasses ]
\end{listing}

\begin{itemize}
\item Conceptually \code{ifTrue:ifFalse:} is a message sent to an object: a boolean!
\item Heavily optimised by the compiler
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Boolean Implementation}

\begin{itemize}
\item \code{true} is the unique instance of the class \code{True}
\item \code{false} is the unique instance of the class \code{False}
\end{itemize}


\begin{center}
\includegraphics[width=0.5\textwidth]{figures/BooleanHiearchyAndInstances.png}\end{center}


More details in a future lecture (The Essence of Dispatch)
\end{frame}



\begin{frame}[fragile]

\frametitle{Conditionals: ifTrue: and ifTrue:ifFalse:}

\code{ifTrue: {[} {]}} and \code{ifTrue: {[} {]} ifFalse: {[} {]}} are two different messages

\begin{listing}{}
forceItalicOrOblique
   self slantValue = 0 
      ifTrue: [ slantValue := 1 ]
\end{listing}

\begin{listing}{}
fullName isEmptyOrNil
   ifTrue: [ 'FirstnameLastname' translated ]
   ifFalse: [ fullName ].
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Conditionals: ifFalse: and ifFalse:ifTrue:}

\code{ifFalse: {[} {]}} and \code{ifFalse: {[} {]} ifTrue: {[} {]}} are two different messages
\end{frame}



\begin{frame}[fragile]

\frametitle{Conditionals: ifEmpty: ifNotEmpty:}

\begin{listing}{}
myProtocol 
   ifEmpty: [ 'As yet unclassified' ]
\end{listing}

\begin{listing}{}
self listItems 
   ifNotEmpty: [ :aList | aList at: index ]
\end{listing}

\begin{itemize}
\item Notice that when the receiver is not empty we get it as argument
\item No need to ask it again
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Summary}

\begin{itemize}
\item Booleans are real objects
\item Some conditionals are messages sent to Booleans
\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:
