|
1 \documentclass{article} |
|
2 \usepackage{../style} |
|
3 \usepackage{../langs} |
|
4 \usepackage{marvosym} |
|
5 \usepackage{tcolorbox} |
|
6 %% \usepackage[]{hvextern} |
|
7 |
|
8 %cheat sheet |
|
9 %http://worldline.github.io/scala-cheatsheet/ |
|
10 |
|
11 \begin{document} |
|
12 \fnote{\copyright{} Christian Urban, King's College London, 2025} |
|
13 |
|
14 \section*{Ammonite ``Quirks''} |
|
15 |
|
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 |
|
23 |
|
24 \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small] |
|
25 $ amm cw02.sc |
|
26 \end{lstlisting} %% $ |
|
27 |
|
28 \noindent |
|
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. |
|
32 |
|
33 \subsection*{Problem with Implicits} |
|
34 |
|
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 |
|
37 |
|
38 \begin{lstlisting}[numbers=none,language=Scala] |
|
39 val KEYWORD : Rexp = "while" | "if" | "then" |
|
40 \end{lstlisting} |
|
41 |
|
42 \noindent with the error |
|
43 |
|
44 \begin{lstlisting}[numbers=none,language=Scala] |
|
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 |
|
59 |
|
60 |
|
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{&}%$: |
|
66 |
|
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) |
|
75 } |
|
76 \end{lstlisting} |
|
77 |
|
78 \noindent You need to then use \code{&} in the code for the |
|
79 \code{WHILE_REGS} |
|
80 |
|
81 \end{document} |
|
82 |
|
83 %%% Local Variables: |
|
84 %%% mode: latex |
|
85 %%% TeX-master: t |
|
86 %%% End: |