Browse Source

Started writing Functions chapter

pull/1/head
Brett Langdon 14 years ago
parent
commit
2b1cd2f056
2 changed files with 28 additions and 1 deletions
  1. +28
    -1
      3 - Functional Programming/1.3 - Functions.tex
  2. BIN
      Programming In General.pdf

+ 28
- 1
3 - Functional Programming/1.3 - Functions.tex View File

@ -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}


BIN
Programming In General.pdf View File


Loading…
Cancel
Save