Commit 405783e6 authored by Michael Kohlhase's avatar Michael Kohlhase

draining

parent bbf6da31
\begin{module}
\usemhmodule[path=python/en/functions]{python-functions}
\begin{frame}[fragile]
\usemhmodule[path=python/en/functions]{python-functions}
\begin{nomtext}
We now come to a general device for organizing and modularizing code provided by most
programming languages, including $\pythonLanguage$. Like
\trefis[python-variables]{variable}, \trefis[python-functions]{function} give names to
$\pythonLanguage$ objects -- here fragments of code -- and thus make them reusable
in other contexts.
\end{nomtext}
\begin{frame}[fragile,allowframebreaks]
\frametitle{Functions in $\pythonLanguage$ (Introduction)}
\begin{itemize}
\item
......@@ -29,17 +37,21 @@ greet(input ("Who are you?"))
...
\end{lstlisting}
\end{example}
\item functions can be a very powerful tool for structuring and documenting
programs\lec{if used correctly}
\item
\begin{example}[title=Multilingual Greeting] given a value for \lstinline|lang|
\begin{lstlisting}
\item functions can be a very powerful tool for structuring and documenting
programs\lec{if used correctly}
\newpage
\item
\begin{example}[title=Multilingual Greeting]
Given a value for \lstinline|lang|
\begin{lstlisting}[mathescape,basicstyle=\small\sf]
def greet (who):
if lang == 'en' :
print("Hello ",who," how are you today? How about some $\text{\useSGvar{courseacronym}}$?")
elif lang == 'de' :
print("Sehr geehrter ",who,", wie geht es Ihnen heute? Wie w\"are es mit $\text{\useSGvar{courseacronym}}$?")
elif lang == 'de' :
print("Sehr geehrter ",who,", wie geht's heute? Wie waere es mit $\text{\useSGvar{courseacronym}}$?")
\end{lstlisting}
we can even localize (i.e. adapt to the language specified in \lstinline|lang|) the
greeting.
\end{example}
\end{itemize}
\end{frame}
......@@ -50,4 +62,5 @@ def greet (who):
%%% TeX-master: t
%%% End:
% LocalWords: usemhmodule python-function.def,id
% LocalWords: usemhmodule python-function.def,id nomtext organizing modularizing trefis
% LocalWords: trefis fragile,allowframebreaks newpage
\begin{module}[id=python-functions]
\importmhmodule[path=python/en/nutshell]{python-nutshell}
\importmhmodule[repos=MiKoMH/KWARC,path=missing/en/pseudocode]{pseudocode}
\importmhmodule[path=python/en/variables]{python-variables}
\lstset{language=python}
\begin{nomtext}
We can now make the intuitions above formal and give the exact $\pythonLanguage$ syntax
of \trefis{function}.
\end{nomtext}
\begin{frame}[fragile]
\frametitle{Functions in $\pythonLanguage$ (Definition)}
\begin{itemize}
......@@ -14,7 +20,7 @@ def $f$ ($p_1$,$\ldots$,$p_n$):
"""
$\pmetavar{body}$ # it can contain $p_1,\ldots,p_n$, and $f$
return $\pmetavar{value}$ # value of the function call (e.g text or number)
$\pmetaver{more code}$
$\pmetavar{more code}$
\end{lstlisting}
\begin{itemize}
\item the indented part is called the \defi{body} of $f$,\lec{\textwarning: whitespace
......
\begin{module}[id=python-libraries]
\importmhmodule[path=python/en/methods]{python-methods}
\importmhmodule[path=python/en/methods]{python-methods}
\importmhmodule[path=python/en/fileio]{python-fileio}
\importmhmodule[repos=MiKoMH/GenCS,path=legal/en/floss-intro]{floss-intro}
\lstset{language=python}
\begin{nomtext}
It is very natural to want to share successful and useful code with others, be it
collaborators in a larger project or company, or the respective community at
large. Given what we have learned so far this is easy to do: we write up the code in a
(collection of) $\pythonLanguage$ files, and make them available for download. Then
others can simply load them via the \lstinline|import| command.
\end{nomtext}
\begin{frame}[label=slide.libraries]
\frametitle{$\pythonLanguage$ Libraries}
\begin{itemize}
\item
\begin{omtext}[title=Idea]
\Trefis[python-functions]{function}, \trefis[python-methods]{classes}, and
\trefis[python-methods]{methods} are re-usable, so why not package them up for
\Trefis[python-functions]{function}, \atrefi[python-methods]{classes}{class}, and
\trefis[python-methods]{method} are re-usable, so why not package them up for
others to use.
\end{omtext}
\item
\begin{definition}
A $\pythonLanguage$ \defi{library} is a $\pythonLanguage$ file with a collection of
\trefis[python-functions]{function}, \trefis[python-methods]{classes}, and
\trefis[python-methods]{methods}. It can be loaded via the \lstinline|import|
\trefis[python-functions]{function}, \atrefi[python-methods]{classes}{class}, and
\trefis[python-methods]{method}. It can be loaded via the \lstinline|import|
command.
\end{definition}
\item There are $\geq 150.000$ libraries for $\pythonLanguage$ \lec{\hateq packages on
......@@ -22,14 +33,28 @@
\item search for them at \url{http://pypi.org}\lec{e.g. 815 packages for ``music''}
\item install them with \lstinline[mathescape]|pip install $\pmetavar{package-name}$|
\item look at how they were done\lec{all have links to source code}
\item maybe even contribute back (report issues, improve code, \ldots)\lec{open
source}
\item maybe even contribute back (report issues, improve code,
\ldots)\lec{\mtrefii[floss-intro?FLOSS]{open}{source}}
\end{itemize}
\end{itemize}
\end{frame}
\begin{nomtext}
The $\pythonLanguage$ community is an \mtrefii[floss-intro?FLOSS]{open}{source}
community, therefore many developers organize their code into libraries and license them
under \mtrefi[floss-intro?FLOSS]{open}{source} \trefis[licensing]{license}.
Software repositories like PyPI (the $\pythonLanguage$ Package Index) collect
(references to) and make them for the package manager \lstinline|pip|, a program that
downloads $\pythonLanguage$ libraries and installs them on the local machine where the
\lstinline|import| command can find them.
\end{nomtext}
\end{module}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
% LocalWords: importmhmodule GenCS,path nomtext Trefis atrefi geq hateq ldots mtrefii
% LocalWords: mtrefi
......@@ -4,6 +4,14 @@
\importmhmodule[repos=MiKoMH/KWARC,path=missing/en/pseudocode]{pseudocode}
\lstset{language=python}
\makeatletter\providecommand\lst@tagresetfirst{}\makeatletter
\begin{nomtext}
$\pythonLanguage$ provides two kinds of function-like facilities: regular
\trefis[python-functions]{function} as discussed above and \trefi{methods}, which come
with $\pythonLanguage$ classes. We will not attempt a presentation of object-oriented
programming and its particular implementation in $\pythonLanguage$ -- this would be
beyond the mandate of the \useSGvar{courseacronym} course -- but give a brief
introduction that is sufficient to use \trefis{method}.
\end{nomtext}
\begin{frame}[fragile,allowframebreaks]
\frametitle{Functions vs. Methods in $\pythonLanguage$}
\begin{itemize}
......@@ -56,6 +64,12 @@
\end{example}
\end{itemize}
\end{frame}
\begin{nomtext}
For the purposes of \useSGvar{courseacronym}, it is sufficient to remember that
\trefis{method} are a special kind of \trefis[python-functions]{function} that employ
the \trefii{dot}{notation}. They are provided by the \trefi{class} of an
\trefi{object}.
\end{nomtext}
\end{module}
%%% Local Variables:
......@@ -64,4 +78,5 @@
%%% End:
% LocalWords: importmhmodule makeatletter providecommand lst@tagresetfirst makeatletter
% LocalWords: trefis sref atrefi ldots defis defii qquad
% LocalWords: trefis sref atrefi ldots defis defii qquad nomtext useSGvar courseacronym
% LocalWords: fragile,allowframebreaks newpage vspace trefii
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment