handouts/pep-ho.tex
changeset 197 c3e39fdeea3b
parent 195 fc3ac7b70a06
child 198 d59c7995bcb2
--- a/handouts/pep-ho.tex	Mon Nov 05 16:05:27 2018 +0000
+++ b/handouts/pep-ho.tex	Wed Nov 07 11:59:16 2018 +0000
@@ -1,3 +1,4 @@
+% !TEX program = xelatex
 \documentclass{article}
 \usepackage{../style}
 \usepackage{../langs}
@@ -16,7 +17,7 @@
 % functional programming in Scala
 %https://www.amazon.com/gp/product/1449311032/ref=as_li_ss_tl?ie=UTF8&tag=aleottshompag-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=1449311032
 
-% functional programmming in C
+% functional programming in C
 %https://www.amazon.com/gp/product/0201419505/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=0201419505&linkCode=as2&tag=aleottshompag-20
 
 %speeding through haskell
@@ -79,12 +80,12 @@
 
 I found a convenient IDE for writing Scala programs is Microsoft's
 \textit{Visual Studio Code} (VS Code) which runs under MacOSX, Linux and
-obviously Windows.\footnote{Unlike \emph{Microsoft Visual Studio}---note
+obviously Windows.\footnote{unlike \emph{Microsoft Visual Studio}---note
 the minuscule difference in the name---which is a heavy-duty,
 Windows-only IDE\ldots{}jeez, with all their money could they not come
 up with a completely different name for a complete different project?
 For the pedantic, Microsoft Visual Studio is an IDE, whereas Visual
-Studio Code is a source code editor. Anybody knows the what the
+Studio Code is considered as a source code editor. Anybody knows the what the
 difference is?} It can be downloaded for free from
 
 \begin{quote}
@@ -119,10 +120,9 @@
 painless to work with Scala completely on the command line (as you might
 have done with \texttt{g++} in the earlier part of PEP). For the
 lazybones among us, there are even online editors and environments for
-developing and running Scala programs called \textit{ScalaFiddle}
-and \textit{Scastie}, which
-require zero setup (assuming you have a browser handy). You can access
-them from: 
+developing and running Scala programs: \textit{ScalaFiddle}
+and \textit{Scastie} are two of them. They require zero setup 
+(assuming you have a browser handy). You can access them at 
  
 \begin{quote}
   \url{https://scalafiddle.io}\\
@@ -130,6 +130,9 @@
 \end{quote}
   
 \noindent
+But you should be careful if you use them for your coursework: they
+are meant to play around, not really for serious work. 
+
 Scala can be used with the heavy-duty IDEs Eclipse and IntelliJ.
 A ready-made Scala bundle for Eclipse is available from
 
@@ -171,8 +174,8 @@
 for example). The main idea of imperative programming  is that you have
 some form of \emph{state} in your program and you continuously change this
 state by issuing some commands---for example for updating a field in an
-array or object, or for adding one to a variable and so on. The classic
-example for this style of programming are \texttt{for}-loops, like
+array or for adding one to a variable and so on. The classic
+example for this style of programming are \texttt{for}-loops in C:
 
 \begin{lstlisting}[language=C,numbers=none]
 for (int i = 10; i < 20; i++) { 
@@ -426,7 +429,8 @@
 \subsection*{Standalone 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
+implement an object that is an instance of \code{App}. For example
+write
 
 \begin{lstlisting}[numbers=none]
 object Hello extends App {
@@ -434,7 +438,7 @@
 }
 \end{lstlisting}
 
-\noindent save it in a file, for example {\tt hello-world.scala}, and
+\noindent save it in a file, say {\tt hello-world.scala}, and
 then run the compiler (\texttt{scalac}) and start the runtime
 environment (\texttt{scala}):
 
@@ -521,8 +525,8 @@
 \noindent
 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}. It is a good habit to include this information
-about the return type always. Simple examples of Scala functions are:
+of type \code{String}. It is a good habit to always include this information
+about the return type. Simple examples of Scala functions are:
 
 \begin{lstlisting}[numbers=none]
 def incr(x: Int) : Int = x + 1
@@ -540,8 +544,9 @@
 \end{lstlisting}
 
 \noindent
-where each argument requires its type and the result type of the
-function, \code{rty}, should be given. If the body of the function is
+where each argument, \texttt{arg1}, \texttt{arg2} and so on, requires 
+its type and the result type of the
+function, \code{rty}, should also 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 (that is call themselves),
@@ -569,9 +574,9 @@
 res1: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8)
 \end{lstlisting}
 
-\noindent Generating from this list, the list of squares in a
-programming language such as Java, you would assume the list
-is given as a kind of array. You would then iterate, or loop,
+\noindent Generating from this list the list of corresponding 
+squares in a programming language such as Java, you would assume 
+the list is given as a kind of array. You would then iterate, or loop,
 an index over this array and replace each entry in the array
 by the square. Right? In Scala, and in other functional
 programming languages, you use maps to achieve the same. 
@@ -590,8 +595,11 @@
 
 \noindent The important keywords are \code{for} and
 \code{yield}. This for-comprehension roughly states that from
-the list of numbers we draw \code{n}s and compute the result
-of \code{n * n}. As you can see, we specified the list where
+the list of numbers we draw elements that are given the name 
+\code{n} and compute the result
+of \code{n * n}. This is a simple example---what comes after 
+\code{yield} can be a complex expression enclosed in \texttt{\{...\}}.
+As you can see, we specified the list where
 each \code{n} comes from, namely \code{(1 to 8).toList}, and
 how each element needs to be transformed. This can also be
 expressed in a second way in Scala by using directly
@@ -679,7 +687,7 @@
 needs to be modified. The reason is that \code{print}, you
 guessed it, does not produce any result, but only produces
 what is in the functional-programming-lingo called a
-side-effect. Printing out the list of numbers from 1 to 5
+\emph{side-effect}. Printing out the list of numbers from 1 to 5
 would look as follows
 
 \begin{lstlisting}[numbers=none]
@@ -693,8 +701,8 @@
 
 \begin{lstlisting}[numbers=none]
 scala> for (n <- (1 to 5).toList) {
-  val square_n = n * n
-  println(s"$n * $n = $square_n") 
+  val square = n * n
+  println(s"$n * $n = $square") 
 }
 1 * 1 = 1
 2 * 2 = 4
@@ -704,7 +712,7 @@
 \end{lstlisting}%$
 
 \noindent In this code I use a variable assignment (\code{val
-square_n = ...} ) and also what is called in Scala a
+square = ...} ) and also what is called in Scala a
 \emph{string interpolation}, written \code{s"..."}. The latter
 is for printing out an equation. It allows me to refer to the
 integer values \code{n} and \code{square\_n} inside a string.
@@ -886,7 +894,7 @@
 the point of having functions as input arguments to other
 functions? In Java there is indeed no need of this kind of
 feature: at least in the past it did not allow such
-constructions. I think, the point of Java 8 is to lift this
+constructions. I think, the point of Java 8 and successors was to lift this
 restriction. But in all functional programming languages,
 including Scala, it is really essential to allow functions as
 input argument. Above you already seen \code{map} and
@@ -1117,17 +1125,18 @@
 % to write this by hand using only the ``plain'' regular
 % expressions from the inductive datatype.
 
-\bigskip\noindent
-\textit{More TBD.}
+%\bigskip\noindent
+%\textit{More TBD.}
 
-\subsection*{Coursework}
+%\subsection*{Coursework}
 
 
 
 \subsection*{More Info}
 
 There is much more to Scala than I can possibly describe in
-this document. Fortunately there are a number of free books
+this document and teach in the lectures. Fortunately there are a 
+number of free books
 about Scala and of course lots of help online. For example
 
 \begin{itemize}
@@ -1139,7 +1148,7 @@
 \item \url{https://twitter.github.io/scala_school}
 \end{itemize}
  
-\noindent There is also a course at Coursera on Functional
+\noindent There is also an online course at Coursera on Functional
 Programming Principles in Scala by Martin Odersky, the main
 developer of the Scala language. And a document that explains
 Scala for Java programmers
@@ -1179,7 +1188,8 @@
 production code, but then moved away from it. Allegedly they did not
 like the steep learning curve of Scala and also that new versions of
 Scala often introduced incompatibilities in old code. Also the Java
-language is lately developing at lightening speed taking on many
+language is lately developing at lightening speed (in comparison to the past) 
+taking on many
 features of Scala and other languages, and it seems even it introduces
 new features on its own.
 
@@ -1194,12 +1204,18 @@
 
 \subsection*{Conclusion}
 
-\begin{itemize}
-\item no exceptions....there two kinds, one ``global'' exceptions, like
-out of memory (not much can be done about this by the ``individual''
-programmer); and ``local one'' open a file that might not exists - in
-the latter you do not want to use exceptions, but Options
-\end{itemize}
+I hope you like the short journey in the Scala World: remember we 
+like you to take on board the functional programming point of view,
+rather than just learning another language. If you moan about all the
+idiotic features of Scala, well that is part of the packaged according
+to this quote:\bigskip
+
+%\begin{itemize}
+%\item no exceptions....there two kinds, one ``global'' exceptions, like
+%out of memory (not much can be done about this by the ``individual''
+%programmer); and ``local one'' open a file that might not exists - in
+%the latter you do not want to use exceptions, but Options
+%\end{itemize}
 
 \begin{flushright}\it
 There are only two kinds of languages: the ones people complain