

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

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{What You Will Learn}

\begin{itemize}
\item How to return a value from a method and a block
\item The default return values
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{4 Cases}

\begin{itemize}
\item Method with a return statement
\item Method without a return statement
\item Block without a return statement
\item Block with a return statement
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Returning a Value From a Method}

Use the caret \code{\string^} to return a value from a method

\begin{listing}{}
Number >> squared
   "Answer the receiver multipled by itself."
   ^ self * self
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Default Method's Return Value}

A method with no caret \code{\string^} returns \code{self}

\begin{listing}{}
Game >> initializePlayers
   self players
      at: 'tileAction'
      put: ...
\end{listing}

is equivalent to

\begin{listing}{}
Game >> initializePlayers
   self players
      at: 'tileAction'
      put: ...
   ^ self       "<-- optional"
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Blocks Return Value}

Blocks return the value of their last expression

\begin{listing}{}
[ :x |
   x + 33.
   x + 2 ] value: 5
> 7
\end{listing}

The caret \code{\string^} in a block has a special meaning...
\end{frame}



\begin{frame}[fragile]

\frametitle{A Caret in a Block Returns from the Method}

A caret \code{\string^} in a block quits the enclosing method

\begin{listing}{}
Integer>>factorial
   "Answer the factorial of the receiver."

   self = 0 ifTrue: [ ^ 1 ].
   self > 0 ifTrue: [ ^ self * (self - 1) factorial ].
   self error: 'Not valid for negative integers'
\end{listing}

\begin{itemize}
\item When returning (with caret \code{\string^}) from a block, the method defining the block is terminated
\item Further readings: \url{http://deepintopharo.org}
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{What you Should Know}

\begin{itemize}
\item The caret \code{\string^} always terminates the method
\item A method returns \code{self} by default
\item A block returns the result of its last expression
\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:
