updated
authorChristian Urban <christian.urban@kcl.ac.uk>
Wed, 01 Nov 2023 15:01:32 +0000
changeset 471 135bf034ac30
parent 470 86a456f8cb92
child 472 6a77c260c8a5
updated
cws/core_cw01.pdf
cws/core_cw01.tex
cws/core_cw02.pdf
cws/core_cw02.tex
cws/core_cw03.tex
cws/disclaimer.sty
handouts/pep-ho.pdf
handouts/pep-ho.tex
handouts/scala-ho.tex
progs/lecture1.scala
progs/lecture2.scala
progs/mandelbrot.scala
Binary file cws/core_cw01.pdf has changed
--- a/cws/core_cw01.tex	Sat Sep 23 23:49:44 2023 +0100
+++ b/cws/core_cw01.tex	Wed Nov 01 15:01:32 2023 +0000
@@ -33,8 +33,8 @@
 \noindent
 In addition, the Scala coursework comes with a reference implementation
 in form of \texttt{jar}-files. This allows you to run any test cases on
-your own computer. For example you can call Scala on the command line
-with the option \texttt{-cp collatz.jar} and then query any function
+your own computer. For example you can call scala-cli on the command line
+with the option \texttt{--extra-jars collatz.jar} and then query any function
 from the template file. Say you want to find out what the functions
 \texttt{collatz} and \texttt{collatz\_max} produce: for this you just
 need to prefix them with the object name \texttt{C1}. If you want to
@@ -42,7 +42,7 @@
 would type something like:
 
 \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
-$ scala -cp collatz.jar
+$ scala-cli --extra-jars collatz.jar
   
 scala> C1.collatz(6)
 ...
Binary file cws/core_cw02.pdf has changed
--- a/cws/core_cw02.tex	Sat Sep 23 23:49:44 2023 +0100
+++ b/cws/core_cw02.tex	Wed Nov 01 15:01:32 2023 +0000
@@ -34,8 +34,8 @@
 \noindent
 In addition, the Scala part comes with reference
 implementations in form of \texttt{jar}-files. This allows you to run
-any test cases on your own computer. For example you can call Scala on
-the command line with the option \texttt{-cp docdiff.jar} and then
+any test cases on your own computer. For example you can call scala-cli on
+the command line with the option \texttt{--extra-jars docdiff.jar} and then
 query any function from the template file. Say you want to find out
 what the function \texttt{occurrences} produces: for this you just need
 to prefix it with the object name \texttt{C2}.  If you want to find out what
@@ -43,7 +43,7 @@
 you would type something like:
 
 \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
-$ scala -cp docdiff.jar
+$ scala-cli --extra-jars docdiff.jar
   
 scala> C2.occurrences(List("a", "b", "b"))
 ...
--- a/cws/core_cw03.tex	Sat Sep 23 23:49:44 2023 +0100
+++ b/cws/core_cw03.tex	Wed Nov 01 15:01:32 2023 +0000
@@ -37,7 +37,7 @@
 This Scala assignment comes with two reference implementations in
 form of \texttt{jar}-files. This allows
 you to run any test cases on your own computer. For example you can
-call Scala on the command line with the option \texttt{-cp
+call scala-cli on the command line with the option \texttt{--extra-jars
   postfix.jar} and then query any function from the
 \texttt{postfix.scala} file (similarly for file \texttt{postfix2.scala}). As
 usual you have to prefix the calls with \texttt{C3a} and
@@ -45,7 +45,7 @@
 
 
 \begin{lstlisting}[xleftmargin=1mm,numbers=none,basicstyle=\ttfamily\small]
-$ scala -cp postfix.jar
+$ scala-cli --extra-jars postfix.jar
 
 scala> C3a.syard(C3a.split("( 5 + 7 ) * 2"))
 val res0: C3a.Toks = List(5, 7, +, 2, *)
--- a/cws/disclaimer.sty	Sat Sep 23 23:49:44 2023 +0100
+++ b/cws/disclaimer.sty	Wed Nov 01 15:01:32 2023 +0000
@@ -4,9 +4,9 @@
 \begin{itemize}
 \item #1  
 \item Make sure the files you submit can be processed by just calling\\
-  \mbox{\texttt{scala <<filename.scala>>}} on the command line.\footnote{All
+  \mbox{\texttt{scala-cli <<filename.scala>>}} on the command line.\footnote{All
     major OSes, including Windows, have a command line. So there is no
-    good reason to not download Scala, install it and run it on your
+    good reason to not download scala-cli, install it and run it on your
     own computer. Just do it!} Use the
   template files provided and do not make any changes to arguments of
   functions or to any types. You are free to implement any auxiliary
@@ -37,9 +37,9 @@
 
 \begin{itemize}
 \item Make sure the files you submit can be processed by just calling\\
-  \mbox{\texttt{scala <<filename.scala>>}} on the command line.\footnote{All
+  \mbox{\texttt{scala-cli <<filename.scala>>}} on the command line.\footnote{All
     major OSes, including Windows, have a command line. So there is no
-    good reason to not download Scala, install it and run it on your
+    good reason to not download scala-cli, install it and run it on your
     own computer. Just do it!} Use the
   template files provided and do not make any changes to arguments of
   functions or to any types. You are free to implement any auxiliary
Binary file handouts/pep-ho.pdf has changed
--- a/handouts/pep-ho.tex	Sat Sep 23 23:49:44 2023 +0100
+++ b/handouts/pep-ho.tex	Wed Nov 01 15:01:32 2023 +0000
@@ -11,7 +11,7 @@
 \newcommand{\annotation}[1]{\hfill\footnotesize{}#1}
 
 \usepackage{menukeys}
-
+\usepackage{emoji}
 
 %cheat sheet
 %http://worldline.github.io/scala-cheatsheet/
@@ -165,7 +165,7 @@
 \end{quote}
 
 \noindent
-The official Scala compiler can be downloaded from
+The official Scala web-page is here:
 
 \begin{quote}
 \url{http://www.scala-lang.org}\medskip
@@ -176,9 +176,22 @@
 the version I am going to use in the lectures and in the coursework. This
 can be any version of Scala 3.X where $X=\{1,2,3\}$. Also the minor
 number does not matter. Note that this will be the first year I am
-using this version -- so some hiccups are bound to happen. Apologies
+using this newer version -- so some hiccups are bound to happen. Apologies
 in advance!\bigskip
 
+\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black]
+  I will be using the \textbf{\texttt{scala-cli}} REPL for scala, rather
+  than the ``plain'' Scala REPL. This is a batteries included version of
+  Scala and is easier to use. In fact \texttt{scala-cli} will replace
+  the ``plain'' Scala REPL in future versions. So why not using it now?
+  It can be downloaded from:
+
+  \begin{center}
+  \url{https://scala-cli.virtuslab.org}  
+  \end{center}  
+\end{tcolorbox}\medskip  
+
+
 \noindent
 If you are interested, there are also experimental backend of Scala
 for generating JavaScript code (\url{https://www.scala-js.org}), and
@@ -218,14 +231,13 @@
 \begin{center}  
 \includegraphics[scale=0.15]{../pics/vscode.png}\\[-10mm]\mbox{}
 \end{center}
-\caption{My installation of VS Code includes the following
-  packages from Marketplace: \textbf{Scala Syntax (official)} 0.5.4,
-  \textbf{Code Runner} 0.11.6, \textbf{Code Spell Checker} 2.0.12,
-  \textbf{Rewrap} 1.14.0 and \textbf{Subtle Match
-  Brackets} 3.0.0. I have also bound the keys \keys{Ctrl} \keys{Ret} to the
+\caption{My installation of VS Code / Codium includes the 
+  package  \textbf{Scala Syntax (official)} 0.5.7 from Marketplace.
+  I have also bound the keys \keys{Ctrl} \keys{Ret} to the
   action ``Run-Selected-Text-In-Active-Terminal'' in order to quickly
-  evaluate small code snippets in the Scala REPL. I use the internal
-  terminal to run Scala 2.13.6.\label{vscode}}
+  evaluate small code snippets in the Scala REPL. I use Codium's internal
+  terminal to run \texttt{scala-cli} version 1.0.5 which
+  uses Scala 3.3.1.\label{vscode}}
 \end{boxedminipage}
 \end{figure}  
 
@@ -241,55 +253,58 @@
 \end{quote}
 
 
-What I like most about VS Code/Codium is that it provides easy access to the
-Scala REPL. But if you prefer another editor for coding, it is also
-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: \textit{ScalaFiddle}
-and \textit{Scastie} are two of them. They require zero setup 
-(assuming you have a browser handy). You can access them at 
+What I like most about VS Code/Codium is that it provides easy access
+to the Scala REPL. But if you prefer another editor for coding, it is
+also 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: \textit{Scastie} and
+\textit{ScalaFiddle} 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}\\
-  \url{https://scastie.scala-lang.org}\medskip
+  \url{https://scastie.scala-lang.org}\\
+  \url{https://scalafiddle.io}\medskip
 \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. 
+are meant to play around, not really for serious work. Make
+sure your \texttt{scala-cli} works on your own machine ASAP!
 
 As one might expect, Scala can be used with the heavy-duty IDEs
-Eclipse and IntelliJ.  A ready-made Scala bundle for Eclipse is
-available from
+Eclipse and IntelliJ. For example IntelliJ includes plugins for
+Scala
 
 \begin{quote}
-\url{http://scala-ide.org/download/sdk.html}
+\url{https://scalacenter.github.io/bloop/docs/ides/intellij}
 \end{quote}
 
 \noindent
-Also IntelliJ includes plugins for Scala. \underline{\textbf{BUT}}, 
-I do \textbf{not} recommend the usage of either Eclipse or IntelliJ for PEP: these IDEs
-seem to make your life harder, rather than easier, for the small
-programs that we will write in this module. They are really meant to be used
-when you have a million-lines codebase instead of our small
-``toy-programs''\ldots{}for example why on earth am I required to create a
-completely new project with several subdirectories when I just want to
-try out 20-lines of Scala code? Your mileage may vary though.~\texttt{;o)}
+\underline{\textbf{BUT}}, I do \textbf{not} recommend the usage of
+either Eclipse or IntelliJ for PEP: these IDEs seem to make your life
+harder, rather than easier, for the small programs that we will write
+in this module. They are really meant to be used when you have a
+million-lines codebase instead of our small
+``toy-programs''\ldots{}for example why on earth am I required to
+create a completely new project with several subdirectories when I
+just want to try out 20-lines of Scala code? Your mileage may vary
+though.~\texttt{;o)}
 
 \subsection*{Why Functional Programming?}
 
 Before we go on, let me explain a bit more why we want to inflict upon
 you another programming language. You hopefully have mastered Java and
-C++\ldots{}the world should be your oyster, no? Well, matters are not as
-simple as one might wish. We do require Scala in PEP, but actually we do
-not religiously care whether you learn Scala---after all it is just a
-programming language (albeit a nifty one IMHO). What we do care about is
-that you learn about \textit{functional programming}. Scala is just the
-vehicle for that. Still, you need to learn Scala well enough to get good
-marks in PEP, but functional programming could perhaps equally be taught
-with Haskell, F\#, SML, Ocaml, Kotlin, Clojure, Scheme, Elm and many
-other functional programming languages. 
+C++, possibly Python\ldots{} the world should be your oyster, no?
+Well, matters are not as simple as one might wish. We do require Scala
+in PEP, but actually we do not religiously care whether you learn
+Scala---after all it is just a programming language (albeit a nifty
+one IMHO). What we do care about is that you learn about
+\textit{functional programming}. Scala is just the vehicle for
+that. Still, you need to learn Scala well enough to get good marks in
+PEP, but functional programming could perhaps equally be taught with
+Haskell, F\#, SML, Ocaml, Kotlin, Clojure, Scheme, Elm and many other
+functional programming languages.
 
 %Your friendly lecturer just
 %happens to like Scala and the Department agreed that it is a good idea
@@ -300,7 +315,7 @@
 might even be totally alien to you. The reason is that functional
 programming seems to go against the core principles of
 \textit{imperative programming} (which is what you do in Java and
-C/C++ for example). The main idea of imperative programming is that
+C/C++). 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 for adding one to a variable
@@ -500,16 +515,16 @@
 command line:
 
 \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
-$ scala
+$ scala-cli
 Welcome to Scala 3.3.1 (17.0.8.1, Java OpenJDK 64-Bit Server VM).
-Type in expressions for evaluation. Or try :help.  
+Type in expressions for evaluation. Or try :help.
 
 scala>
 \end{lstlisting}%$
 
 \noindent The precise response may vary depending
 on the version and platform where you installed Scala. Make sure
-you have installed Scala version 3. At the Scala
+\texttt{scala-cli} uses Scala version 3. At the Scala
 prompt you can type things like \code{2 + 3}\;\keys{Ret} and
 the output will be
 
@@ -532,26 +547,26 @@
 Another classic example you can try out is
 
 \begin{lstlisting}[numbers=none,language={}]
-scala> print("hello world")
+scala> println("hello world")
 hello world
 \end{lstlisting}
 
 \noindent Note that in this case there is no result. The
-reason is that \code{print} does not actually produce a result
+reason is that \code{println} does not actually produce a result
 (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
 between a function that returns a result, like addition, and a
-function that causes a side-effect, like \code{print}. We
+function that causes a side-effect, like \code{println}. 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. It is just not printed by Scala. 
 
-You can try more examples with the Scala REPL, but feel free to
+You can try more examples with the \texttt{scala-cli} REPL, but feel free to
 first guess what the result is (not all answers by Scala are obvious):
 
-\begin{lstlisting}[numbers=none]
+\begin{lstlisting}[numbers=none,language={}]
 scala> 2 + 2
 scala> 1 / 2
 scala> 1.0 / 2
@@ -591,40 +606,38 @@
 \subsection*{Standalone Scala Apps}
 
 If you want to write a standalone app in Scala, you can
-implement an object that is an instance of \code{App}. For example
-write
+implement a function \texttt{hello} and annotate the tag
+\texttt{@main}. For example write
 
 \begin{lstlisting}[numbers=none]
-object Hello extends App {
-    println("hello world")
-}
+@main 
+def Hello() = println("hello world")
 \end{lstlisting}
 
+%object Hello extends App {
+%    println("hello world")
+%}
+
 \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}):
+then use \texttt{scala-cli run} (which internally compiles the
+scala file and runs it):
 
 \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
-$ scalac hello-world.scala
-$ scala Hello
+$ scala-cli run hello-world.scala
 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
-scala-library.jar}, which on my computer can be done as
-follows:
+Runtime. This can be done as follows:
 
 \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
-$ scalac hello-world.scala
-$ java -cp /usr/local/src/scala/lib/scala-library.jar:. Hello
+$ scala-cli --power package --assembly hello-world.scala
+$ java -jar Hello.jar
 hello world
 \end{lstlisting}
 
-\noindent You might need to adapt the path to where you have
-installed Scala.
 
 \subsection*{Values}
 
@@ -749,10 +762,55 @@
 
 \noindent
 but this seems a bit overkill for a small function like \code{fact}.
-Notice that Scala does not have a \code{then}-keyword in an
-\code{if}-statement. Also important is that there should be always an
-\code{else}-branch. Never write an \code{if} without an \code{else},
-unless you know what you are doing! While \code{def} is the main
+Notice that I did not use a \code{then}-keyword in the
+\code{if}-statements and that I enclosed the condition inside
+parentheses, like \code{(n == 0)}. Your eyes might hurt to not see an
+\code{else} with an \code{if}, but this has been long established
+syntax for \code{if}-statements. Scala, to my knowledge, was pretty
+unique in that for nearly 20 years of its existence\ldots{}until Scala
+3 came along. While people like me have perfectly adapted to the sight
+of \code{if}s without \code{then}s, it seems the developers of Scala
+caved in to the special eyesight of Gen-Python people and now allow to
+write the same function also as
+
+\begin{lstlisting}[numbers=none]
+def fact(n: Int) : Int = {
+  if n == 0 then 1 
+  else n * fact(n - 1)
+}    
+\end{lstlisting}
+
+\noindent
+I accept this might look a bit more familiar to beginners of Scala, if
+they come from other languages, like Java or C++. But that we also had
+to get rid in Scala 3 of the familiar \texttt{\{\}}-parentheses is
+completely beyond me. So in Scala 3 the braces are optional and the
+\texttt{fact}-function can even be written as
+
+\begin{lstlisting}[numbers=none]
+def fact(n: Int) : Int = 
+     if n == 0 then 1 
+     else n * fact(n - 1)
+\end{lstlisting}
+
+\noindent on the condition that indents now become \emph{meaningful}
+(as in Python).\raisebox{-0.7mm}{\emoji{face-vomiting}} All versions are now permitted in Scala 3. While you
+are free to use any syntax version you want in PEP, or even mix them,
+I will \textbf{not} show you any of my code in the newfangled
+Pythonesque meaningful-indent-syntax. When necessary, I will always
+use braces to indicate the beginning and end of a code block, and I
+have not yet get used to the \code{if}s with
+\code{then}s.\footnote{Scala adopted some very fine features of Python, for example string interpolations, but that we had to completely cave in to
+  the demands of Gen-Python is a step to far for my completely
+  insignificant opinion. For me this is a bridge too far.
+  I always assumed escaping Python's dependency hell
+is every software developers life goal---apparently not. ;o)}
+
+
+However, no matter which syntax style you adopt for \code{if}s, never
+write an \code{if} without an \code{else}-branch! That has something
+to do with functional programming and you will see its purpose later
+on. Coming back to function definitions: While \code{def} is the main
 mechanism for defining functions, there are a few other ways for doing
 this. We will see some of them in the next sections.
 
@@ -1401,7 +1459,7 @@
 by looking into the documentation
 
 \begin{quote}
-\url{http://www.scala-lang.org/api/current/}
+\url{https://dotty.epfl.ch/api/index.html}
 \end{quote}
 
 The function arrow can also be iterated, as in 
@@ -1843,11 +1901,14 @@
 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 (in comparison to the past) 
-taking on many
-features of Scala and other languages, and it seems it even introduces
-new features on its own. So there is seemingly even more incentive to
-stick with the old stuff you know.
+language is lately developing at lightening speed (in comparison to
+the past) taking on many features of Scala and other languages, and it
+seems it even introduces new features on its own. So there is
+seemingly even more incentive to stick with the old stuff you
+know. Still, the goal of this part of PEP is to bend your mind about
+what programming is\ldots{}namely functional programming. I promise
+you, this will be useful no matter with which programming language you
+will work.
 
 
 Scala is deep: After many years, I still continue to learn new technique
@@ -1884,7 +1945,7 @@
 He makes pretty much the same arguments about functional programming and
 immutability (one section is teasingly called \textit{``Where Did all
 the Bugs Go?''}). If you happen to moan about all the idiotic features
-of Scala, well, I guess this is part of the package according to this
+of Scala (3), well, I guess this is part of the package according to this
 quote:\bigskip
 
 %\begin{itemize}
--- a/handouts/scala-ho.tex	Sat Sep 23 23:49:44 2023 +0100
+++ b/handouts/scala-ho.tex	Wed Nov 01 15:01:32 2023 +0000
@@ -12,7 +12,7 @@
 
 \begin{document} 
 
-\section*{A Crash-Course on Scala}
+\section*{A Crash-Course of Scala}
 
 Scala is a programming language that combines functional and
 object-oriented programming-styles. It has received quite a bit of
--- a/progs/lecture1.scala	Sat Sep 23 23:49:44 2023 +0100
+++ b/progs/lecture1.scala	Wed Nov 01 15:01:32 2023 +0000
@@ -5,20 +5,11 @@
 // - Value assignments (val vs var)
 // - How to define functions? (What is returned?)
 // - If-Conditions
-
-val tmp = 0
-val result = !(tmp == 0)
-val result = if (tmp == 0) true else false
-
-//        expressions (if (tmp == 0) true else false)
 // - For-Comprehensions (guards, with/without yield)
+// - String-Interpolations
 //
 //
-// - Options
-// - Higher-Order Functions (short-hand notation)
-// - maps (behind for-comprehensions)
-// - Pattern-Matching
-// - String-Interpolations
+
 
 // Value assignments
 // (their names should be lower case)
@@ -29,13 +20,14 @@
 val y = 3 + 4 
 val z = x / y
 val x = 70
-print(z)
+println(z)
 
 
 // (you cannot reassign values: z = 9 will give an error)
 //var z = 9
 //z = 10
 
+
 // Hello World
 //=============
 
@@ -92,7 +84,7 @@
 
 // Equality in Scala is structural
 //=================================
-val a = "Dave2"
+val a = "Dave"
 val b = "Dave"
 
 if (a == b) println("Equal") else println("Unequal")
@@ -151,8 +143,8 @@
 1F  // a Float
 1D  // a Double
 
-// useful list methods on lists
-//==============================
+// useful methods for lists
+//=========================
 
 List(1,2,3,4).length
 List(1,2,3,4).reverse
@@ -200,14 +192,14 @@
 val name : String = "bob"
 
 // type errors
-math.sqrt("64".toDouble)
+math.sqrt("64")
 
 // produces
 //
-// error: type mismatch;
-// found   : String("64")
-// required: Double
-// math.sqrt("64")
+// Type Mismatch Error:
+//   Found   : ("64" : String)
+//   Required: Double
+//
 
 
 // Pairs/Tuples
@@ -245,7 +237,7 @@
 // type to each argument and a return type of the function
 //
 //  def fname(arg1: ty1, arg2: ty2,..., argn: tyn): rty = {
-//    
+//     ....
 //  }
 
 
@@ -253,12 +245,18 @@
 // If-Conditionals
 //=================
 
-// - Scala does not have a then-keyword
+// - Scala used to not have a then-keyword
 // - !!both if-else branches need to be present!!
 
 def fact(n: Int) : Int = 
   if (n == 0) 1 else n * fact(n - 1)
 
+
+// Scala 3 introduced if-then-else - maybe people 
+// desperately needed it 
+def fact(n: Int) : Int = 
+  if n == 0 then 1 else n * fact(n - 1)
+
 fact(5)
 fact(150)
 
@@ -271,7 +269,6 @@
 */
 
 
-
 def fib(n: Int) : Int = {
   if (n == 0) 1 else
     if (n == 1) 1 else fib(n - 1) + fib(n - 2)
@@ -280,8 +277,6 @@
 fib(9)
 
 
-
-
 //gcd - Euclid's algorithm
 
 def gcd(a: Int, b: Int) : Int = {
@@ -306,8 +301,9 @@
   else xs.sum / xs.length
 }
 
+average(List(3,4,5))
 average(List())
-
+average(Nil)
 
 
 // For-Comprehensions (not For-Loops)
@@ -377,12 +373,14 @@
 
 for (n <- (1 to 10).toList) yield n * n
 
+
 // BTW: a roundabout way of printing out a list, say
 val lst = ('a' to 'm').toList
 
 for (i <- (0 until lst.length)) println(lst(i))
 
-// Why not just? Why making your life so complicated?
+// ...why not just the following? Why making your life 
+// so complicated?
 for (c <- lst) println(c)
 
 
@@ -414,7 +412,7 @@
 
 
 // Aside: concurrency 
-// scala -Yrepl-class-based -cp scala-parallel-collections_2.13-0.2.0.jar 
+// scala-cli --extra-jars scala-parallel-collections_3-1.0.4.jar 
 
 for (n <- (1 to 10)) println(n)
 
@@ -431,7 +429,7 @@
   (end - start) / 1.0e9
 }
 
-val list = (1 to 1000000).toList
+val list = (1L to 10_000_000L).toList
 time_needed(10, for (n <- list) yield n + 42)
 time_needed(10, for (n <- list.par) yield n + 42)
 
@@ -456,9 +454,9 @@
 
 var cnt = 0
 
-for(i <- (1 to 1000000).par) cnt += 1
+for(i <- (1 to 100_000).par) cnt += 1
 
-println(s"Should be 1 Mio: $cnt")
+println(s"Should be 100000: $cnt")
 
 
 
@@ -469,7 +467,7 @@
 
 def count_intersection(A: Set[Int], B: Set[Int]) : Int = {
   var count = 0
-  for (x <- A.par; if (B contains x)) count += 1 
+  for (x <- A.par; if B contains x) count += 1 
   count
 }
 
@@ -488,44 +486,66 @@
 count_intersection2(A, B)
 
 
-//another bad example
-def test() = {
-  var cnt = 0
-  for(i <- (1 to 1000000).par) cnt += 1
-  println(cnt)
-}
+
+// String Interpolations
+//=======================
+
+def cube(n: Int) : Int = n * n * n
+
+val n = 3
+println("The cube of " + n + " is " + cube(n) + ".")
+
+println(s"The cube of $n is ${cube(n)}.")
 
-test()
+// or even
+
+println(s"The cube of $n is ${n * n * n}.")
+
+// helpful for debugging purposes
+//
+//     "The most effective debugging tool is still careful 
+//          thought, coupled with judiciously placed print 
+//                                             statements."
+//       — Brian W. Kernighan, in Unix for Beginners (1979)
 
 
 
-// Regular Expressions (the built in ones)
+def gcd_db(a: Int, b: Int) : Int = {
+  println(s"Function called with $a and $b.")
+  if (b == 0) a else gcd_db(b, a % b)
+}
 
-val s = """Any so-called "politician" should respect a vote."""
-print(s)
+gcd_db(48, 18)
 
-print("""foo""")
+// you can also implement your own string interpolations
 
-val reg = """\d+""".r
+extension (sc: StringContext) {
+    def i(args: Any*): String = s"\t${sc.s(args:_*)}\n"
+    def l(args: Any*): String = s"${sc.s(args:_*)}:\n"
+}
 
-reg.findAllIn("bbbbaaabbbaaaccc").toList
-reg.replaceAllIn("bbbbaaabbbaaaccc", "*")
-reg.replaceAllIn("bbbb0aaa1bbba2aac3cc", "_")
-reg.replaceAllIn("bbbb00aaa11bbba232aac33cc", "_")
+// this allows you to write things like
 
+i"add ${3+2}" 
+l"some_fresh_name"
 
 // Further Information
 //=====================
 
+// We are going to use Scala 3 and the scala-cli repl (easier to use)
+//
+//  https://scala-cli.virtuslab.org
+//
+//
 // The Scala homepage and general information is at
 //
 //  http://www.scala-lang.org
 //	http://docs.scala-lang.org
 //
 //
-// It should be fairly easy to install the Scala binary and
+// It should be fairly easy to install the scala-cli binary and
 // run Scala on the commandline. People also use Scala with 
-// Vim and Jedit. I currently settled on VS Code
+// Vim and Jedit. I currently settled on Codium
 //
 //   https://code.visualstudio.com
 //
@@ -542,7 +562,7 @@
 // Scala Library Docs
 //====================
 //
-//  http://www.scala-lang.org/api/current/
+//  https://dotty.epfl.ch/api/index.html
 //
 // Scala Tutorials
 //
@@ -550,6 +570,6 @@
 //
 // There are also a massive number of Scala tutorials on youtube
 // and there are tons of books and free material. Google is your 
-// friend.
+// friend. Just make sure you follow newer material about Scala 3.
 
 
--- a/progs/lecture2.scala	Sat Sep 23 23:49:44 2023 +0100
+++ b/progs/lecture2.scala	Wed Nov 01 15:01:32 2023 +0000
@@ -1,54 +1,11 @@
 // Scala Lecture 2
 //=================
  
-
-// String Interpolations
-//=======================
-
-def cube(n: Int) : Int = n * n * n
-
-val n = 3
-println("The cube of " + n + " is " + cube(n) + ".")
-
-println(s"The cube of $n is ${cube(n)}.")
-
-// or even
-
-println(s"The cube of $n is ${n * n * n}.")
-
-// helpful for debugging purposes
-//
-//     "The most effective debugging tool is still careful 
-//          thought, coupled with judiciously placed print 
-//                                             statements."
-//       — Brian W. Kernighan, in Unix for Beginners (1979)
-
-
-def gcd_db(a: Int, b: Int) : Int = {
-  println(s"Function called with $a and $b.")
-  if (b == 0) a else gcd_db(b, a % b)
-}
-
-gcd_db(48, 18)
-
-
-
-// you can also implement your own string interpolations
-
-import scala.language.implicitConversions
-import scala.language.reflectiveCalls
-
-implicit def sring_inters(sc: StringContext) = new {
-    def i(args: Any*): String = s"\t${sc.s(args:_*)}\n"
-    def l(args: Any*): String = s"${sc.s(args:_*)}:\n"
-}
-
-// this allows you to write things like
-
-i"add ${3+2}" 
-l"some_fresh_name"
-
-
+// - Options
+// - Higher-Order Functions (short-hand notation)
+// - maps (behind for-comprehensions)
+// - Pattern-Matching
+// - Recursion
 
 // The Option Type
 //=================
@@ -79,6 +36,7 @@
 safe_div(10 + 5, 4 - 1)  
 
 List(1,2,3,4,5,6).indexOf(7)
+List[Int]().min
 List[Int]().minOption
 
 def my_min(ls: List[Int]) : Option[Int] = 
@@ -92,8 +50,8 @@
 //  Try(something).getOrElse(what_to_do_in_case_of_an_exception)
 //
 
-import scala.util._
-import io.Source
+import scala.util._      // Try,...
+import io.Source         // fromURL
 
 val my_url = "https://nms.kcl.ac.uk/christian.urban/"
 
@@ -399,9 +357,10 @@
 // Pattern Matching
 //==================
 
-// A powerful tool which is supposed to come to Java in 
-// a few years time (https://www.youtube.com/watch?v=oGll155-vuQ).
-// ...Scala already has it for many years ;o)
+// A powerful tool which has even landed in Java during 
+// the last few years (https://inside.java/2021/06/13/podcast-017/).
+// ...Scala already has it for many years and the concept is
+// older than your friendly lecturer, that is stone old  ;o)
 
 // The general schema:
 //
@@ -420,8 +379,8 @@
     case x::xs => f(x)::my_map_int(xs, f)
   }
 
-def my_map_option(o: Option[Int], f: Int => Int) : Option[Int] = 
-  o match {
+def my_map_option(opt: Option[Int], f: Int => Int) : Option[Int] = 
+  opt match {
     case None => None
     case Some(x) => Some(f(x))
   }
--- a/progs/mandelbrot.scala	Sat Sep 23 23:49:44 2023 +0100
+++ b/progs/mandelbrot.scala	Wed Nov 01 15:01:32 2023 +0000
@@ -5,7 +5,9 @@
 // 
 // needs to be called with
 // 
-// scala -cp scala-parallel-collections_3-1.0.4.jar
+// scala-cli --extra-jars scala-parallel-collections_3-1.0.4.jar
+//
+// the library is also uploaded to KEATS 
 //
 // !! UPDATE: On my faster Mac-M1 machine the times
 // !! are ca. 4 secs for the sequential version and
@@ -92,7 +94,8 @@
   viewer.canvas.setRGB(x, y, color.getRGB())
 
 
-// calculates the number of iterations using lazy lists (streams)
+// calculates the number of iterations using lazy lists 
+// (streams)
 //   the iteration goes on for a maximum of max steps,
 //   but might leave early when the pred is satisfied
 def iterations(c: Complex, max: Int) : Int = {
@@ -165,10 +168,10 @@
 
 val delta = (exc2 - exc1) * 0.0333
 
-//println(s"${time_needed(
-//  for (n <- (0 to 12)) 
-//     mandelbrot(exc1 + delta * n, 
-//                exc2 - delta * n, 100))} secs") 
+println(s"${time_needed(
+  for (n <- (0 to 12)) 
+     mandelbrot(exc1 + delta * n, 
+                exc2 - delta * n, 100))} secs")