diff --git a/3 - Functional Programming/1.3 - Functions.tex b/3 - Functional Programming/1.3 - Functions.tex index 54a34c1..db1bb3a 100644 --- a/3 - Functional Programming/1.3 - Functions.tex +++ b/3 - Functional Programming/1.3 - Functions.tex @@ -1,5 +1,32 @@ - \subsection{Declaration} +What is a Function? +We have been learning Functional programming, how come we haven't come across Functions until now? +Because I said so. +\par + +A Function allows use to assign a block of code to a name which allows us to eaily repeat the execution of that code without having +to retype the code. +Consider the code. + +\begin{lstlisting}[caption={Function Candidate Example}] +def PrintHello(): + print ``Hello'' + +PrintHello() +print ``Goodbye'' +PrintHello() +Print ``I said Goodbye!'' +\end{lstlisting} + +This code will output the following:\\ +\pigOut{Hello\\ +Goodbye\\ +Hello\\ +I said Goodbye!}\\ +As you can see we are declaring a Function called \pigVar{PrintHello} with the code block \pigVar{print ``Hello''}. +As may have noticed when the code gets to the declaration of the Function it does not execute the code block, instead it +saves the code block for execution later when the Function name is called. +To call the function we use the Function name followed by opening and closing parentheses, \pigVar{PrintHello()}. \subsection{Returns} diff --git a/Programming In General.pdf b/Programming In General.pdf index 9740d7d..e1e89b1 100644 Binary files a/Programming In General.pdf and b/Programming In General.pdf differ