

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

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{What Definitions Say: Reflection}

\textit{Reflection is the ability of a program to manipulate as data something representing the state of the program during its own execution.}

\begin{itemize}
\item \textbf{Introspection} is the ability for a program to \textbf{observe} and therefore \textbf{reason} about its own state.
\item \textbf{Intercession} is the ability for a program to \textbf{modify} its own execution state or alter its own interpretation or meaning.
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{What Definitions Say: Reification}

\textbf{Reification} is the process to transform implicit to explicit (objects)

\begin{itemize}
\item i.e., getting the stack as an object
\item i.e., getting a class as an object
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Pharo is a Reflective System}

\textit{A system having itself as application domain and that is causally connected with this domain can be qualified as a reflective system} Maes'87

\begin{itemize}
\item A reflective system has an internal representation of itself
\item A reflective system is able to act on itself with the ensurance that its representation will be causally connected (i.e. up to date)
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Inspector}

How does it access internal object state?


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

\end{frame}



\begin{frame}[fragile]

\frametitle{State Introspection}

Accessing and setting object state

\begin{listing}{}
Object >> instVarAt: aNumber
Object >> instVarAt: aNumber put: anObject
Object >> instVarNamed: aString
Object >> instVarNamed: aString put: anObject
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Accessing/Setting State Example}

\begin{listing}{}
pt := 10@3.
pt instVarNamed: 'x'.
> 10 
pt instVarNamed: 'x' put: 33.
pt
> 33@3
\end{listing}

\begin{itemize}
\item Violates encapsulation 
\item But this is for tools and during development
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Accessing Class}

\begin{listing}{}
Object >> class
\end{listing}

\begin{listing}{}
'hello' class
(10@3) class
Smalltalk class
Class class
Class class class
Class class class class
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Querying the System}

\begin{listing}{}
OrderedCollection allSuperclasses size.
OrderedCollection allSelectors size.
OrderedCollection allInstVarNames size.
OrderedCollection selectors size.
OrderedCollection instVarNames size.
OrderedCollection subclasses size.
OrderedCollection allSubclasses size.
OrderedCollection linesOfCode.
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Querying the System}

\begin{listing}{}
SystemNavigation default browseAllImplementorsOf: #,
\end{listing}


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

\end{frame}



\begin{frame}[fragile]

\frametitle{Sending a Message by its Name}

\begin{itemize}
\item How to implement a menu or a button?
\item Need to send a message to a receiver given a message selector
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Sending a Message by its Name}

\begin{listing}{}
Object >> perform: aSymbol 
Object >> perform: aSymbol with: arg
\end{listing}

\begin{itemize}
\item Asks an object to execute a message
\item Normal lookup is performed
\end{itemize}

\begin{listing}{}
5 factorial
5 perform: #factorial
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Classes Hold Compiled Methods}


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

\end{frame}



\begin{frame}[fragile]

\frametitle{Executing a Compiled Method}

\begin{listing}{}
CompiledMethod >> valueWithReceiver:arguments:
\end{listing}

\begin{itemize}
\item no lookup performed
\end{itemize}

\begin{listing}{}
(Integer>>#factorial)
  valueWithReceiver: 5 arguments: #()
\end{listing}

\begin{listing}{}
(SmallInteger>>#factorial)
  valueWithReceiver: 5 arguments: #()
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Summary}

\begin{itemize}
\item Just a part of the reflective power!
\item Everything is an object and can be introspected
\item Grab objects and talk to them 
\item Have a look at inspector code
\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:
