summaryrefslogtreecommitdiff
path: root/advanced_python/5_closures.tex
diff options
context:
space:
mode:
authorPrabhu Ramachandran2018-05-15 21:27:57 +0530
committerPrabhu Ramachandran2018-05-15 21:27:57 +0530
commit9132e564c5f28f1b10d66d8323ad765f9d914231 (patch)
tree677edccb6687c8d13f1b3914c896c3a6e8ea55cd /advanced_python/5_closures.tex
parente805f9daa6c91a88fe7c0106db32369b457eda63 (diff)
downloadpython-workshops-9132e564c5f28f1b10d66d8323ad765f9d914231.tar.gz
python-workshops-9132e564c5f28f1b10d66d8323ad765f9d914231.tar.bz2
python-workshops-9132e564c5f28f1b10d66d8323ad765f9d914231.zip
Cleanup the numbering for advanced slides.
Diffstat (limited to 'advanced_python/5_closures.tex')
-rw-r--r--advanced_python/5_closures.tex105
1 files changed, 0 insertions, 105 deletions
diff --git a/advanced_python/5_closures.tex b/advanced_python/5_closures.tex
deleted file mode 100644
index f3571ef..0000000
--- a/advanced_python/5_closures.tex
+++ /dev/null
@@ -1,105 +0,0 @@
-\documentclass[14pt,compress,aspectratio=169]{beamer}
-
-\input{macros.tex}
-
-\title[Closures]{Advanced Python}
-\subtitle{Closures}
-
-\author[FOSSEE] {The FOSSEE Group}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {Mumbai, India}
-
-\begin{document}
-
-\begin{frame}
- \titlepage
-\end{frame}
-
-\begin{frame}
- \frametitle{Overview}
- \begin{itemize}
- \item Higher-order functions
- \item Closures
- \end{itemize}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Recap of higher-order functions}
- \begin{lstlisting}
-In []: def sqr(x):
- ...: return x*x
-
-In []: def sum(func, n):
- ...: result = 0
- ...: for i in range(n):
- ...: result += func(i)
- ...: return result
-
-In []: sum(sqr, 5)
-Out[]: 30
- \end{lstlisting}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Recap of higher-order functions}
- \begin{lstlisting}
-def f():
- def g(x):
- return x+1
- return g
-
-In []: func = f()
-In []: func(1)
-In []: f()(1) # Also valid!
- \end{lstlisting}
-\end{frame}
-
-
-\begin{frame}[fragile]
- \frametitle{Closures}
- \begin{lstlisting}
-def mul(x):
- def g(y):
- return y*x
- return g
-
-In []: twice = mul(2.0)
-In []: twice(20)
-Out[]: 40.0
- \end{lstlisting}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Closures ...}
- \begin{lstlisting}
-
-In []: thrice = mul(3.0)
-In []: thrice(20)
-Out[]: 60.0
- \end{lstlisting}
-\end{frame}
-
-\begin{frame}
- \frametitle{Discussion}
- \begin{itemize}
- \item \typ{g} uses \typ{x}
- \item \typ{x} is different in each case
- \item So \typ{twice, thrice} ``curry'' the passed \typ{x}
- \item This function is called a closure
- \item Encloses its local environment
- \end{itemize}
-\end{frame}
-
-
-\begin{frame}[fragile]
- \frametitle{Summary: Higher-order functions}
- \begin{itemize}
- \item Functions that manipulate functions
- \item Passing a function as an argument
- \item A function that returns another function
- \item A closure
- \end{itemize}
-\end{frame}
-
-\end{document}