Skip to content

Commit

Permalink
bulk fix, last things before final print
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornregnell committed Aug 16, 2023
1 parent 00252d7 commit bc770e9
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 23 deletions.
2 changes: 1 addition & 1 deletion compendium/examples/AliensOnEarth.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object AliensOnEarth:
def readChoice(msg: String, options: Vector[String]): String =
options.indices.foreach(i => println(s"$i: ${options(i)}"))
val selected = io.StdIn.readLine(msg).toInt
val selected = scala.io.StdIn.readLine(msg).toInt
options(selected)

def isAnswerYes(msg: String): Boolean =
Expand Down
2 changes: 1 addition & 1 deletion compendium/modules/w01-intro-exercise.tex
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@
\begin{table}[H]
\begin{longtable}{l l}\small
\begin{longtable}{l l}
\code|fram(100)| & Paddan går framåt 100 steg (25 om argument saknas).\\
\code|färg(rosa)| & Sätter pennans färg till rosa. \\
\code|fyll(lila)| & Sätter ifyllnadsfärgen till lila. \\
Expand Down
4 changes: 2 additions & 2 deletions compendium/modules/w02-programs-exercise.tex
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@
\SetKwInOut{Input}{Indata}\SetKwInOut{Output}{Utdata}

\Input{Array $args$ med strängar som alla innehåller heltal}
\Output{Utskrift av största heltalet }
\Output{största heltalet }
$max \leftarrow$ det minsta heltalet som kan uppkomma \\
$n \leftarrow $ antalet heltal \\
$i \leftarrow 0$ \\
Expand Down Expand Up @@ -663,7 +663,7 @@
\If{xs(i) < $xs(minPos)$}{$minPos \leftarrow i$}
$i \leftarrow i + 1$
}
\eIf{$n > 0$}{\Return{$minPos$}}{\Return{$-1$}}
\eIf{$n > 0$}{$minPos$}{$-1$}
\end{algorithm}

\Subtask Prova algoritmen med penna och papper på sekvensen $(1, 2, -1, 4)$ och rita minnessituationen efter varje runda i loopen. Vad blir skillnaden i exekveringsförloppet om loopvariablen $i$ initialiserats till $0$ i stället för $1$?
Expand Down
2 changes: 1 addition & 1 deletion compendium/modules/w03-functions-exercise.tex
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@

\item När jag kodar har jag REPL igång i ett eget terminalfönster och api-dokumentationen för Scala i en webbläsare redo för sökningar. Jag återanvänder också användbara snuttar från kod jag gjort tidigare och inspireras ofta av lösningar från \url{https://stackoverflow.com} (om jag kan begripa dem och de verkar rimliga).

\item Detta arbetssätt tar ett tag att komma in i, men är ett bra sätt att uppfinna allt större och bättre program. Ett stort program byggs lättast i små inkrement och felsökning blir mycket lättare om man bara gör små tillägg åt gången.
\item Detta arbetssätt tar ett tag att komma in i, men är ett bra sätt att uppfinna allt större och bättre program. Ett stort program byggs lättast i små steg och felsökning blir mycket lättare om man bara gör små tillägg åt gången.

\item Du får också det mycket lättare att förstå ditt program om du delar upp koden i många korta funktioner med bra namn. Du kan sedan lättare hitta på mer avancerade funktioner genom att återanvända befintliga.

Expand Down
2 changes: 1 addition & 1 deletion compendium/modules/w12-assignment-photo.tex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ \subsection{Bakgrund}
grundfärgerna: (0, 0, 0) är helt svart, (255, 255, 255) är helt vitt.

I detta projekt kommer vi skapa matriser av heltal för att beräkna intressanta egenskaper hos en bild, till exempel intensiteten för varje pixel.
För att spara plats vid bearbetning av stora bilder så använder vi, heltalsmatriser med typen \code{Short}, som använder 16 bitar i minnet, i ståället för \code{Int}, som använder 64 bitar i minnet.
För att spara plats vid bearbetning av stora bilder så använder vi, heltalsmatriser med typen \code{Short}, som använder 16 bitar i minnet, i ståället för \code{Int}, som använder 32 bitar i minnet.

\subsection{Förberedelser}

Expand Down
2 changes: 1 addition & 1 deletion compendium/postchapters/build.tex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ \section{Vad gör ett byggverktyg?}

\section{Scala Command Line Interface \texttt{scala-cli}}\label{appendix:build:scala-cli}

Utvecklingen av \href{https://scala-cli.virtuslab.org/}{Scala CLI} påbörjades 2022 av \href{https://virtuslab.com/}{Virtuslab}. Scala CLI blev 2023 det officiella byggverktyget för enkla Scala-projekt och medföljer \href{https://www.scala-lang.org/download/}{installationen av Scala}. Scala CLI kan även installeras separat och köras med kommandot \code{scala-cli}, men blir under 2023 liktydigt med kommandot \code{scala} i terminalen.\footnote{I skrivande stund har gamla \code{scala}-kommandot ännu inte uppgraderats, men det förväntas ske innan höstterminen startar. När så väl sker kan alla förekomster av \code{scala-cli} i detta stycke ersättas med det kortare kommandot \code{scala}.}
Utvecklingen av \href{https://scala-cli.virtuslab.org/}{Scala CLI} påbörjades 2022 av \href{https://virtuslab.com/}{Virtuslab}. Scala CLI blir under 2023 det officiella byggverktyget för enkla Scala-projekt och kommer medfölja \href{https://www.scala-lang.org/download/}{installationen av Scala}. Scala CLI kan även installeras separat och köras med kommandot \code{scala-cli}, men blir någon gång under 2023 liktydigt med kommandot \code{scala} i terminalen.\footnote{I skrivande stund har gamla \code{scala}-kommandot ännu inte uppgraderats, men det förväntas ske i början av hösten. När så väl sker kan alla förekomster av \code{scala-cli} i detta stycke ersättas med det kortare kommandot \code{scala}, efter uppdatering.}

Efter nyinstallation av Scala CLI kan du ange följande kommando för att, en gång för alla, få tillgång till kompletteringar av optioner med Tab-tangenten i terminalen:
\begin{REPLsmall}
Expand Down
28 changes: 14 additions & 14 deletions quickref/quickref.tex
Original file line number Diff line number Diff line change
Expand Up @@ -315,25 +315,25 @@
\code|final| & definitions & \Comment{Final members cannot be overridden, final classes cannot be extended.}\\
\code|protected|~~ & definitions& \Comment{Restricts access to subtypes and companion.}\\
\code|lazy| & val definitions & \Comment{Delays initialization of val, initialized when first referenced.}\\
\code|infix| & def definitions & \Comment{Allow alpha-numeric functions in operator notation without warning.}\\
\code|infix| & def definitions & \Comment{Allow alpha-numeric function names in operator notation without warning.}\\
\code|abstract| & class definitions & \Comment{Abstract classes cannot be instantiated (redundant for traits).}\\
\code|sealed| & class definitions & \Comment{Restricts direct inheritance to classes in the same source file.}\\
\code|sealed| & class definitions & \Comment{Restricts direct inheritance to classes in the same compilation unit.}\\
\code|open| & class definitions & \Comment{Signal intent to be used in inheritance hierarchy. Silences warning.} \\
\end{tabular}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage\vspace*{-2.0em}\head{Constructors and special methods (getters, setters, apply, update), Companion object}\Newline
{\small
\begin{tabular}{@{}l @{}l}
\code|class A(initX: Int = 0):| & \Comment{\textbf{primary constructor}, new is optional creating objects: A(1), default arg: A()} \\
\code|class A(initX: Int = 0):| & \Comment{\textbf{primary constructor}, object creation (new is optional): new A(1), A(1), A()} \\
\code| private var _x = initX| & \Comment{private member only visible in A and its companion object} \\
\code| def x: Int = _x| & \Comment{getter for private field \_x (name with \_ chosen to avoid clash with x)} \\
\code| def x_=(i: Int): Unit = | & \Comment{special setter syntax to update attribute using assignment:} \\
\code| _x = i | & \Comment{val a = A(1); a.x = 2} \\ \vspace{0.4em}
\code|end A| & \Comment{optional end marker checked by compiler, also allowed: \texttt{end class}} \\
\code|end A| & \Comment{optional end marker checked by compiler} \\
\code|object A: | & \Comment{becomes a \textbf{companion object} if same name and in same code file} \\
\code| def apply(i: Int = 0) = | & \Comment{apply is optional: A.apply(1), A(1), A()} \\
\code| new A(i) | & \Comment{new is needed here to avoid recursive calls} \\
\code| new A(i) | & \Comment{\code|new| is needed here to avoid recursive calls} \\
\code| val y = A(1)._x | & \Comment{private members can be accessed in companion} \\
\end{tabular}

Expand All @@ -360,7 +360,7 @@
\Comment{Special syntax for \textbf{update} and \textbf{apply}:} \\
v(0) = 0~\Comment{expanded to} v.update(0,0)\\
v(0)\hspace{1.5em}\Comment{expanded to} v.apply(0)\\
\Comment{where} val v = new IntVec(Array(1,2,3)) \\
\Comment{where} val v = IntVec(Array(1,2,3)) \\

}%
\end{minipage}
Expand Down Expand Up @@ -394,14 +394,14 @@
\vspace{0.25em}\renewcommand{\arraystretch}{1.05}
\begin{tabular}{@{}l @{\hspace{-1.6em}}r @{\hspace{0.6em}}l | r l}

Evaluation order & \code|(1 + 2) * 3| & \Comment{parenthesis control order} & \multicolumn{2}{l}{\hspace{-0.2em}\textbf{Precedence} of operators beginning with:}\\
Evaluation order & \code|(1 + 2) * 3| & \Comment{parenthesis control order} & \multicolumn{2}{l}{\hspace{-0.2em}\textbf{Precedence} of operators starting with:}\\

Method application & \code|1.+(2)| & \Comment{call method + on object 1} & all letters & \textbf{lowest}\\

Operator notation & \code|1 + 2| & \Comment{same as 1.+(2)} & \code+|+ \\

Conjunction & \code|c1 && c2| & \Comment{true if both c1 \textbf{and} c2 true} & \code|^| \\
Disjunction & \code+c1 || c2+ & \Comment{true if c1 \textbf{or} c2 true} & \code|&| \\
Disjunction & \code+c1 || c2+ & \Comment{true if at least one of c1 \textbf{or} c2 true} & \code|&| \\
Negation & \code|!c| & \Comment{logical \textbf{not}, false if c is true} & \code|= !| \\

Function application & \code|f(1, 2, 3)| & \Comment{same as f.apply(1,2,3)} & \code|< >|\\
Expand All @@ -419,7 +419,7 @@
Assignment operator & \code|x += 1| & \multicolumn{3}{l}{\hspace{-0.7em}\Comment{expands to~~\code|x = x + 1|~~if no method += is available, works for all operators}} \\
\vspace{-0.4em}\\
Empty tuple, unit value& \code|()| & \Comment{the only value of type Unit} & \multicolumn{2}{l}{\textbf{Integer division and remainder:}} \\
2-tuple value & \code|(1, "hello")| & \Comment{same as Tuple2(1, "hello")} & \multicolumn{2}{l}{\code|a / b| \Comment{~no decimals if a, b Int, Short, Byte }} \\ \vspace{0.5em}
2-tuple value & \code|(1, "hello")| & \Comment{same as Tuple2(1, "hello")} & \multicolumn{2}{l}{\code|a / b| \Comment{~no decimals if Int, Short, Byte }} \\ \vspace{0.5em}
2-tuple type & \code|(Int, String)| & \Comment{same as Tuple2[Int, String]} & \multicolumn{2}{l}{\code|a \% b| \Comment{~fulfills: (a / b) * b + (a \% b) == a}} \\
\multicolumn{5}{l}{\hspace{-0.7em}Tuple prepend~~~\code|3 *: (1.0, '!')| ~\Comment{of type \texttt{Int\,*:\,Double\,*:\,Char\,*:\,EmptyTuple}~~same as (Int, Double, Char)}}\\
\multicolumn{5}{l}{\hspace{-0.7em}Methods on tuples:~~\code|apply drop take head tail zip toArray toIArray toList| }
Expand Down Expand Up @@ -523,7 +523,7 @@
\code|val b = Box(0) |
& \Comment{same as (with explicit type parameters):~~~val b: Box\textbf{[Int]} = new Box\textbf{[Int]}(0)}\\

\code|val p: (Box[Int], Box[char]) = b.pair(Box('!')) |
\code|val p: (Box[Int], Box[Char]) = b.pair(Box('!')) |
& \Comment{\textbf{type bounds} \code|>:| supertype~~\code|<:| subtype}\\

\end{tabular}
Expand All @@ -550,13 +550,13 @@
\multicolumn{2}{l}{\hspace{-0.62em}\code|val opt: Option[String] = if math.random() > 0.9 then Some("bingo") else None|} \\

\code|opt.getOrElse(expr)|
& \Comment{x: T if opt == Some[T](x) else expr}\\
& \Comment{if opt == Some[T] then x else expr}\\

\code|opt.map(x => ... }|
& \Comment{apply x => ... to x if opt is Some(x) else None}\\
\code|opt.map(f}|
& \Comment{if opt == Some(x) then f(x) else None}\\

\code|opt.get|
& \Comment{x: T if Some[T](x) else throws NoSuchElementException}\\
& \Comment{if opt == Some[T] then x else throws NoSuchElementException}\\
\end{tabular}

\begin{tabular}{@{}l @{\hspace{1.0em}}r}
Expand Down
2 changes: 1 addition & 1 deletion slides/body/lect-w02-codestruct.tex
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@
\SetKwInOut{Input}{Indata}\SetKwInOut{Output}{Utdata}
\Input{Array $args$ med strängar som alla innehåller heltal}
\Output{utskrift av minsta heltalet }
\Output{minsta heltalet }
~\\
$min \leftarrow$ det största heltalet som kan uppkomma \\
$n \leftarrow $ antalet heltal \\
Expand Down
22 changes: 22 additions & 0 deletions slides/body/lect-w07-seq-append-insert-remove.tex
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
\item \code{PolygonWindow} nedan är ett fönster som kan rita en polygon.
\end{itemize}

\ifkompendium
\scalainputlisting[numbers=left,numberstyle=,basicstyle=\fontsize{10}{12}\ttfamily\selectfont]{../compendium/examples/sequences/PolygonWindow.scala}

\vspace{-0em}\scalainputlisting[numbers=left,numberstyle=,basicstyle=\fontsize{10}{12}\ttfamily\selectfont]{../compendium/examples/sequences/PolygonTest.scala}
\else
\vspace{-0.5em}\scalainputlisting[numbers=left,numberstyle=,basicstyle=\fontsize{6.5}{8}\ttfamily\selectfont]{../compendium/examples/sequences/PolygonWindow.scala}
\pause
\vspace{-0em}\scalainputlisting[numbers=left,numberstyle=,basicstyle=\fontsize{6.5}{8}\ttfamily\selectfont]{../compendium/examples/sequences/PolygonTest.scala}
\fi
\end{Slide}


Expand Down Expand Up @@ -51,7 +57,15 @@


\begin{Slide}{Exempel: PolygonArray, ändring på plats}
\ifkompendium
\scalainputlisting[numbers=left,numberstyle=,basicstyle=\fontsize{10}{12}\ttfamily\selectfont]{../compendium/examples/sequences/PolygonArray.scala}
\begin{itemize}
\item Från början är \code{points} fylld med null.
\item Variabeln \code{n} håller reda på hur många som verkligen används.
\end{itemize}
\else
\vspace{-0.6em}\scalainputlisting[numbers=left,numberstyle=,basicstyle=\fontsize{6.5}{7.7}\ttfamily\selectfont]{../compendium/examples/sequences/PolygonArray.scala}
\fi
\end{Slide}

% \begin{Slide}{Test av PolygonArray, ändring på plats}
Expand All @@ -60,7 +74,11 @@


\begin{Slide}{Exempel: PolygonVector, variabel referens till oföränderlig datastruktur}
\ifkompendium
\scalainputlisting[numbers=left,numberstyle=,basicstyle=\fontsize{9.5}{11.5}\ttfamily\selectfont]{../compendium/examples/workspace/w05-seqalg/src/PolygonVector.scala}
\else
\vspace{-0.6em}\scalainputlisting[numbers=left,numberstyle=,basicstyle=\fontsize{6.5}{7.7}\ttfamily\selectfont]{../compendium/examples/workspace/w05-seqalg/src/PolygonVector.scala}
\fi
\end{Slide}

% \begin{Slide}{Test av PolygonVector, variabel referens till oföränderlig datastruktur}
Expand All @@ -69,7 +87,11 @@


\begin{Slide}{Exempel: Polygon som oföränderlig case class}
\ifkompendium
\scalainputlisting[numbers=left,numberstyle=,basicstyle=\fontsize{10}{12}\ttfamily\selectfont]{../compendium/examples/sequences/Polygon.scala}
\else
\vspace{-0.6em}\scalainputlisting[numbers=left,numberstyle=,basicstyle=\fontsize{6.5}{7.7}\ttfamily\selectfont]{../compendium/examples/sequences/Polygon.scala}
\fi
% \begin{itemize}\SlideFontTiny
% \item Nu är attributet points en publik \code{val} som vi kan dela med oss av eftersom datastrukturen \code{Vector} är oföränderlig.
%
Expand Down
4 changes: 4 additions & 0 deletions slides/body/lect-w07-seq-insert-remove-copy.tex
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@
\end{Slide}

\begin{Slide}{Insättning/borttagning i kopia av primitiv Array}
\ifkompendium
\scalainputlisting[numbers=left,numberstyle=,basicstyle=\fontsize{9.5}{11.5}\ttfamily\selectfont]{../compendium/examples/sequences/PointSeqUtils.scala}
\else
\vspace{-0.6em}\scalainputlisting[numbers=left,numberstyle=,basicstyle=\fontsize{6}{7.2}\ttfamily\selectfont]{../compendium/examples/sequences/PointSeqUtils.scala}
\fi

\pause
\SlideFontSmall Man gör \Alert{mycket lätt fel} på gränser/specialfall: +-1, to/until, tom sekvens etc.
Expand Down
2 changes: 1 addition & 1 deletion slides/body/lect-w13-on-demand.tex
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
% \end{itemize}
% \end{Slide}

\begin{Slide}{Repetitionsämnen på begäran 2022}
\begin{Slide}{Repetitionsämnen på begäran från tidigare år}
\begin{enumerate}\SlideFontSmall
\item namnanrop, värdeanrop \Vecka{03}
\item funktionsvärde, funktionstyp och thunk \Vecka{03}
Expand Down

0 comments on commit bc770e9

Please sign in to comment.