# HG changeset patch # User Christian Urban # Date 1703463055 -3600 # Node ID 769bda18a43dcd17dc1f667b2f2b7a5204215751 # Parent e03a0100ec467ce8a56b909838d865ac627448d7 updated jars diff -r e03a0100ec46 -r 769bda18a43d core_solution1/collatz.jar Binary file core_solution1/collatz.jar has changed diff -r e03a0100ec46 -r 769bda18a43d core_solution2/docdiff.jar Binary file core_solution2/docdiff.jar has changed diff -r e03a0100ec46 -r 769bda18a43d core_solution3/postfix.jar Binary file core_solution3/postfix.jar has changed diff -r e03a0100ec46 -r 769bda18a43d core_solution3/postfix2.jar Binary file core_solution3/postfix2.jar has changed diff -r e03a0100ec46 -r 769bda18a43d core_templates1/collatz.jar Binary file core_templates1/collatz.jar has changed diff -r e03a0100ec46 -r 769bda18a43d core_templates2/docdiff.jar Binary file core_templates2/docdiff.jar has changed diff -r e03a0100ec46 -r 769bda18a43d core_templates2/docdiff.scala --- a/core_templates2/docdiff.scala Fri Dec 08 00:54:36 2023 +0000 +++ b/core_templates2/docdiff.scala Mon Dec 25 01:10:55 2023 +0100 @@ -8,7 +8,7 @@ //====================== //(1) -def clean(s: String) : List[String] = ??? +def clean(s: String) : List[String] = List("bla") diff -r e03a0100ec46 -r 769bda18a43d core_templates3/postfix.jar Binary file core_templates3/postfix.jar has changed diff -r e03a0100ec46 -r 769bda18a43d core_templates3/postfix2.jar Binary file core_templates3/postfix2.jar has changed diff -r e03a0100ec46 -r 769bda18a43d main_solution3/re.jar Binary file main_solution3/re.jar has changed diff -r e03a0100ec46 -r 769bda18a43d main_solution5/bfc.scala --- a/main_solution5/bfc.scala Fri Dec 08 00:54:36 2023 +0000 +++ b/main_solution5/bfc.scala Mon Dec 25 01:10:55 2023 +0100 @@ -304,7 +304,7 @@ } -/* + @main def main() = { import M5b._ println(time_needed(1, run(load_bff("mandelbrot.bf")))) @@ -312,4 +312,4 @@ println(time_needed(1, run3(load_bff("mandelbrot.bf")))) println(time_needed(1, run4(load_bff("mandelbrot.bf")))) } -*/ + diff -r e03a0100ec46 -r 769bda18a43d main_templates2/wordle.jar Binary file main_templates2/wordle.jar has changed diff -r e03a0100ec46 -r 769bda18a43d main_templates3/re.jar Binary file main_templates3/re.jar has changed diff -r e03a0100ec46 -r 769bda18a43d main_templates4/shogun.jar Binary file main_templates4/shogun.jar has changed diff -r e03a0100ec46 -r 769bda18a43d main_templates5/bf.jar Binary file main_templates5/bf.jar has changed diff -r e03a0100ec46 -r 769bda18a43d main_templates5/bfc.jar Binary file main_templates5/bfc.jar has changed diff -r e03a0100ec46 -r 769bda18a43d main_testing5/bfc_test.sh --- a/main_testing5/bfc_test.sh Fri Dec 08 00:54:36 2023 +0000 +++ b/main_testing5/bfc_test.sh Mon Dec 25 01:10:55 2023 +0100 @@ -19,7 +19,7 @@ # functional tests function scala_assert { - (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli -i "$1" "$2" -e "urbanmain()" 2> /dev/null 1> /dev/null) + (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli -i "$1" "$2" -e "urbanmain()")# 2> /dev/null 1> /dev/null) } # purity test diff -r e03a0100ec46 -r 769bda18a43d progs/lecture5.scala --- a/progs/lecture5.scala Fri Dec 08 00:54:36 2023 +0000 +++ b/progs/lecture5.scala Mon Dec 25 01:10:55 2023 +0100 @@ -1,6 +1,15 @@ // Scala Lecture 5 //================= +for (n <- (1 to 10).toList) yield { + val add = 10 + n + add +} + +println(add) + +List(1,2,3,4).sum + // extension methods // implicit conversions // (Immutable) OOP @@ -11,14 +20,14 @@ // Extensions or How to Pimp your Library //====================================== -// + // For example adding your own methods to Strings: // Imagine you want to increment strings, like // // "HAL".increment // // you can avoid ugly fudges, like a MyString, by -// using implicit conversions. +// using extensions. extension (s: String) { def increment = s.map(c => (c + 1).toChar) @@ -28,6 +37,7 @@ +// a more relevant example import scala.concurrent.duration.{TimeUnit,SECONDS,MINUTES} @@ -45,8 +55,12 @@ 5.seconds + 2.minutes //Duration(125, SECONDS ) +// Implicit Conversions +//===================== + + + // Regular expressions - the power of DSLs in Scala -// and Laziness //================================================== abstract class Rexp @@ -57,6 +71,8 @@ case class SEQ(r1: Rexp, r2: Rexp) extends Rexp // sequence r1 . r2 case class STAR(r: Rexp) extends Rexp // star r* +val r = STAR(CHAR('a')) + // some convenience for typing in regular expressions import scala.language.implicitConversions @@ -76,7 +92,11 @@ def ~ (s: Rexp) = SEQ(r, s) } +val r1 = CHAR('a') | CHAR('b') | CHAR('c') +val r2 = CHAR('a') ~ CHAR('b') +val r3 : Rexp = "hello world" + //example regular expressions val digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" diff -r e03a0100ec46 -r 769bda18a43d slides/slides05.pdf Binary file slides/slides05.pdf has changed diff -r e03a0100ec46 -r 769bda18a43d slides/slides05.tex --- a/slides/slides05.tex Fri Dec 08 00:54:36 2023 +0000 +++ b/slides/slides05.tex Mon Dec 25 01:10:55 2023 +0100 @@ -164,7 +164,7 @@ %Office: & N\liningnums{7.07} (North Wing, Bush House)\bigskip\\ Slides \& Code: & KEATS\bigskip\\ - Office Hour: & Fridays 11:00 -- 12:00\\ + Office Hour: & Fridays 13:00 -- 14:00\\ Location: & N7.07 (North Wing, Bush House)\bigskip\\ Pollev: & \texttt{\alert{https://pollev.com/cfltutoratki576}}\\ \\ @@ -183,13 +183,13 @@ \begin{minipage}{1.2\textwidth} \begin{itemize} \item SGTs still ongoing next week -\item LGT next week online: Ask-Me-Anything (will be recorded, TEAMS link will be emailed and published on KEATS) -\item tests might break over Christmas +%\item LGT next week online: Ask-Me-Anything (will be recorded, TEAMS link will be emailed and published on KEATS) +%\item tests might break over Christmas \end{itemize}\bigskip -\begin{center} -\raisebox{-9mm}{\includegraphics[scale=0.15]{../pics/thanks.jpeg}} Junhuai Hou \quad Chin Wan -\end{center} +%\begin{center} +%\raisebox{-9mm}{\includegraphics[scale=0.15]{../pics/thanks.jpeg}} Junhuai Hou \quad Chin Wan +%\end{center} \end{minipage} @@ -197,14 +197,14 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\begin{frame}[c] -\frametitle{Main 4: \knight-Tour} - -\begin{center} -\Large\bf hint -\end{center} - -\end{frame} +%\begin{frame}[c] +%\frametitle{Main 4: \knight-Tour} +% +%\begin{center} +%\Large\bf hint +%\end{center} +% +%\end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -312,17 +312,17 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\begin{frame}[c] -\frametitle{Plan for Today} +%\begin{frame}[c] +%\frametitle{Plan for Today} +% +%\begin{itemize} +%\item Polymorphic Types +%\item Implicits +%\item Immutable OOP +%%\item Making Fun about Scala +%\end{itemize} -\begin{itemize} -\item Polymorphic Types -\item Implicits -\item Immutable OOP -%%\item Making Fun about Scala -\end{itemize} - -\end{frame} +%\end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%