--- a/handouts/pep-ho.tex Thu Nov 02 14:47:55 2017 +0000
+++ b/handouts/pep-ho.tex Sat Nov 04 16:17:19 2017 +0000
@@ -38,9 +38,10 @@
res0: Int = 5
\end{lstlisting}
-\noindent indicating that the result of the addition is of
-type \code{Int} and the actual result is 5. Another classic
-example you can try out is
+\noindent indicating that the result of the addition is of type
+\code{Int} and the actual result is 5; \code{res0} is a name that
+Scala gives automatically to the result. Yoy can reuse this name later
+on. Another classic example you can try out is
\begin{lstlisting}[numbers=none]
scala> print("hello world")
@@ -49,7 +50,7 @@
\noindent Note that in this case there is no result. The
reason is that \code{print} does not actually produce a result
-(there is no \code{resXX} and no type), rather it is a
+(there is no \code{resX} and no type), rather it is a
function that causes the \emph{side-effect} of printing out a
string. Once you are more familiar with the functional
programming-style, you will know what the difference is
@@ -57,7 +58,7 @@
function that causes a side-effect, like \code{print}. We
shall come back to this point later, but if you are curious
now, the latter kind of functions always has \code{Unit} as
-return type.
+return type. It is just not printed.
You can try more examples with the Scala interpreter, but try
first to guess what the result is (not all answers by Scala are obvious):
@@ -75,7 +76,7 @@
scala> "12345".length
\end{lstlisting}
-\subsection*{Stand-Alone Apps}
+\subsection*{Stand-Alone Scala Apps}
If you want to write a stand-alone app in Scala, you can
implement an object that is an instance of \code{App}, say
@@ -86,7 +87,7 @@
}
\end{lstlisting}
-\noindent save it in a file, say {\tt hello-world.scala}, and
+\noindent save it in a file, for example {\tt hello-world.scala}, and
then run the compiler and runtime environment:
\begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
@@ -95,6 +96,7 @@
hello world
\end{lstlisting}
+\noindent
Like Java, Scala targets the JVM and consequently
Scala programs can also be executed by the bog-standard Java
Runtime. This only requires the inclusion of {\tt
@@ -112,10 +114,10 @@
\subsection*{Values}
-In the lectures, I will try as much as possible to avoid the term
-\emph{variables} familiar from other programming languages. Scala
-has \emph{values}, which can be seen as abbreviations of larger
-expressions. For example
+In the lectures I will try to avoid as much as possible the term
+\emph{variables} familiar from other programming languages. The reason
+is that Scala has \emph{values}, which can be seen as abbreviations of
+larger expressions. For example
\begin{lstlisting}[numbers=none]
scala> val x = 42
@@ -130,8 +132,8 @@
\noindent
Why the kerfuffle about values? Well, values are \emph{immutable}. You cannot
-change their value after you defined them. If you try to reassign, say,
-\code{z}, Scala will yell at you:
+change their value after you defined them. If you try to reassign
+\code{z} above, Scala will yell at you:
\begin{lstlisting}[numbers=none]
scala> z = 9
@@ -151,7 +153,7 @@
scala> println(z)
\end{lstlisting}
-\noindent but try to guess what Scala will print out in the code above
+\noindent but try to guess what Scala will print out
for \code{z}? Will it be \code{6} or \code{10}? A final word about
values: Try to stick to the convention that names of values should be
lower case, like \code{x}, \code{y}, \code{foo41} and so on.
@@ -159,7 +161,8 @@
\subsection*{Function Definitions}
-A function \code{f} taking a single argument of type \code{Int} can be defined
+We do functional programming. So defining functions will be our main occupation.
+A function \code{f} taking a single argument of type \code{Int} can be defined in Scala
as follows:
\begin{lstlisting}[numbers=none]
@@ -167,9 +170,10 @@
\end{lstlisting}
\noindent
-It returns the value resulting from evaluating the expression
+This function returns the value resulting from evaluating the expression
\code{EXPR} (whatever is substituted for this). The result will be
-of type \code{String}. Simple examples of Scala functions are:
+of type \code{String}. It is a good habbit to include this information
+about the return type always. Simple examples of Scala functions are:
\begin{lstlisting}[numbers=none]
def incr(x: Int) : Int = x + 1
@@ -188,10 +192,11 @@
\noindent
where each argument requires its type and the result type of the
-function, \code{rty}, shoudl be given. If the body of the function
-is more complex, then it can be enclosed in braces; it it is just a
-simple expression, like \code{x + 1}, you can omit the braces. Very
-often functions are recursive (call themselves) like
+function, \code{rty}, should be given. If the body of the function is
+more complex, then it can be enclosed in braces, like above. If it it
+is just a simple expression, like \code{x + 1}, you can omit the
+braces. Very often functions are recursive (call themselves) like
+the venerable factorial function.
\begin{lstlisting}[numbers=none]
def fact(n: Int): Int =