754
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1 |
\documentclass{article}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
2 |
\usepackage{../style}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
3 |
\usepackage{../langs}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
4 |
\usepackage{marvosym}
|
|
917
|
5 |
\usepackage{tcolorbox}
|
|
|
6 |
%% \usepackage[]{hvextern}
|
754
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
7 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
8 |
%cheat sheet
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
9 |
%http://worldline.github.io/scala-cheatsheet/
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
10 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
11 |
\begin{document}
|
|
1016
|
12 |
\fnote{\copyright{} Christian Urban, King's College London, 2025}
|
754
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
13 |
|
|
1016
|
14 |
\section*{Ammonite ``Quirks''}
|
|
917
|
15 |
|
|
1016
|
16 |
While Ammonite is great when it comes to additional features, such as
|
|
|
17 |
multiple main's and dynamically loading files, and in the past it was
|
|
|
18 |
a rock-solid piece of software written by one of my Scala-heroes
|
|
|
19 |
(Haoyi Li), it seems it has acquired some ``quirks'' when it
|
|
|
20 |
transitioned to Scala 3. Interestingly, the problems listed below only occur
|
|
|
21 |
inside the REPL. So running Scala-scripts on the command
|
|
|
22 |
line with for example
|
754
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
23 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
24 |
\begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
|
|
1016
|
25 |
$ amm cw02.sc
|
754
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
26 |
\end{lstlisting} %% $
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
27 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
28 |
\noindent
|
|
1016
|
29 |
works fine. Similarly, the original Scala REPL seems to not suffer
|
|
|
30 |
from these quirks. Unfortunately, this REPL does not allow you to
|
|
|
31 |
dynamically load files which might be relevant in later CWs.
|
754
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
32 |
|
|
1016
|
33 |
\subsection*{Problem with Implicits}
|
754
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
34 |
|
|
1016
|
35 |
In CW2 (and possibly others), if you use the template code and develop
|
|
|
36 |
your code inside the REPL, a problem arises in the line
|
754
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
37 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
38 |
\begin{lstlisting}[numbers=none,language=Scala]
|
|
1016
|
39 |
val KEYWORD : Rexp = "while" | "if" | "then"
|
|
|
40 |
\end{lstlisting}
|
754
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
41 |
|
|
1016
|
42 |
\noindent with the error
|
|
760
|
43 |
|
|
|
44 |
\begin{lstlisting}[numbers=none,language=Scala]
|
|
1016
|
45 |
-- [E008] Not Found Error: cmd17.sc:1:36 -----------------------------
|
|
|
46 |
1 |val KEYWORD : Rexp = "while" | "if" | "then"
|
|
|
47 |
| ^^^^^^^^^^^^^^^^
|
|
|
48 |
|value | is not a member of ammonite.$sess.cmd4.ALT.
|
|
|
49 |
|An extension method was tried, but could not be fully constructed:
|
|
|
50 |
|
|
|
|
51 |
| ammonite.$sess.cmd16.|()
|
|
|
52 |
|
|
|
|
53 |
| failed with:
|
|
|
54 |
|
|
|
|
55 |
| value |: <overloaded ammonite.$sess.cmd16.|> does not take
|
|
|
56 |
| parameters
|
|
|
57 |
|Compilation Failed
|
|
|
58 |
\end{lstlisting}%$\medskip
|
754
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
59 |
|
|
994
|
60 |
|
|
1016
|
61 |
\noindent\textbf{Fix:} The code runs absolutely fine when called on the
|
|
|
62 |
commandline. It also runs absolutely fine inside the standard Scala REPL.
|
|
|
63 |
If you prefer to use to use the Ammonite REPL, then you need to make the
|
|
|
64 |
following changes: (1) comment out the implicits below and change the
|
|
|
65 |
\code{$} to for example \code{&}%$:
|
|
994
|
66 |
|
|
1016
|
67 |
\begin{lstlisting}[numbers=none,language=Scala]
|
|
|
68 |
extension (s: String) {
|
|
|
69 |
def & (r: Rexp) = RECD(s, r)
|
|
|
70 |
//def | (r: Rexp) = ALT(s, r)
|
|
|
71 |
//def | (r: String) = ALT(s, r)
|
|
|
72 |
//def % = STAR(s)
|
|
|
73 |
//def ~ (r: Rexp) = SEQ(s, r)
|
|
|
74 |
//def ~ (r: String) = SEQ(s, r)
|
|
994
|
75 |
}
|
|
1016
|
76 |
\end{lstlisting}
|
|
994
|
77 |
|
|
1016
|
78 |
\noindent You need to then use \code{&} in the code for the
|
|
|
79 |
\code{WHILE_REGS}
|
|
994
|
80 |
|
754
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
81 |
\end{document}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
82 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
83 |
%%% Local Variables:
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
84 |
%%% mode: latex
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
85 |
%%% TeX-master: t
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
86 |
%%% End:
|