handouts/amm-ho.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Wed, 25 Oct 2023 13:54:11 +0100
changeset 944 f5d2453c5640
parent 936 0b5f06539a84
child 965 94f5cce73a4f
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
\documentclass{article}
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
\usepackage{../style}
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
\usepackage{../langs}
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
\usepackage{marvosym}
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
     5
\usepackage{tcolorbox}
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
     6
%% \usepackage[]{hvextern}
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
%cheat sheet
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
%http://worldline.github.io/scala-cheatsheet/
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
\begin{document}
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    12
\fnote{\copyright{} Christian Urban, King's College London, 2020, 2021, 2023}
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    13
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    14
\section*{Scala 3 in 6CCS3CFL}
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    15
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    16
For the coursework in this module you are free to use any programming
756
f7c7a75e0583 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 755
diff changeset
    17
language you like, but I will show you all my code using Scala---I
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    18
hope you have fond memories of Scala from PEP. The only difference
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    19
with PEP is that I will use the current
924
6ad0f63e1968 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 917
diff changeset
    20
stable version of Scala, which at the time of writing is Scala 3.3.1.
830
dbf9d710ce65 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 760
diff changeset
    21
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    22
\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black]
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    23
If you intend to submit your code for the CW in Scala, you \underline{MUST} submit code that
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    24
is compatible with Scala 3!! This is to make it easier for me to test
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    25
your code and the changes between Scala 2 from last year PEP to Scala
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    26
3 in CFL are not that great. In fact, most changes are just some new
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    27
syntax.
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    28
\end{tcolorbox}\medskip
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    29
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    30
\noindent
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    31
If you need a reminder of the Scala handouts from PEP updated to Scala 3
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    32
have a look here
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    33
\hr{http://talisker.nms.kcl.ac.uk/cgi-bin/repos.cgi/pep-material/raw-file/tip/handouts/pep-ho.pdf}. But as said, you do not need to use Scala for the CWs.\footnote{Haskell, Rust, Ocaml were other languages that have
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    34
  been used previously in CFL. I do not recommend to use Java or C or C++ for
830
dbf9d710ce65 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 760
diff changeset
    35
  writing a compiler, but if you insist, feel free. It has been done
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    36
  before.}  
830
dbf9d710ce65 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 760
diff changeset
    37
\bigskip
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    38
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    39
\noindent
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    40
The other difference between the Scala I showed you in PEP is that in CFL
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    41
I will use the Ammonite REPL (with underlying Scala Version 3):
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    42
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    43
\begin{quote}
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    44
\url{https://ammonite.io/#Ammonite-REPL}
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    45
\end{quote}
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    46
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    47
\noindent
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    48
This is a drop-in replacement for the original Scala REPL and
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    49
works very similarly, for example
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    50
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    51
\begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    52
$ amm
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    53
Loading...
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    54
Welcome to the Ammonite Repl 2.5.9 (Scala 3.2.2 Java 17.0.7)
830
dbf9d710ce65 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 760
diff changeset
    55
scala> 1 + 2
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    56
res0: Int = 3
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    57
\end{lstlisting} %% $
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    58
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    59
%%\runExtCmd[redirect]{ls -la}{voss}
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    60
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    61
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    62
\noindent
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    63
Ammonite uses the same Scala compiler, just adds some useful features
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    64
on top of it. It is quite main-stream in the Scala community and it should
838
97df390d64f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 830
diff changeset
    65
therefore be very easy for you to install \texttt{amm}. If you work under
97df390d64f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 830
diff changeset
    66
a Unix-like system, a sure way to install the right version of Ammonite
97df390d64f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 830
diff changeset
    67
is by using \texttt{curl}:
97df390d64f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 830
diff changeset
    68
97df390d64f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 830
diff changeset
    69
\begin{lstlisting}[numbers=none,language={},basicstyle=\ttfamily\small]
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    70
$ curl -L https://github.com/com-lihaoyi/Ammonite/releases/\
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    71
  download/2.5.9/3.2-2.5.9 --output amm
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    72
\end{lstlisting} %% $  
838
97df390d64f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 830
diff changeset
    73
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    74
\noindent
924
6ad0f63e1968 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 917
diff changeset
    75
This creates a file \code{amm} which before it can be run might
936
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
    76
need some adjustments of the permissions. Under recent versions of
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
    77
Windows also have \texttt{curl}, but need a slightly different call:
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
    78
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
    79
\begin{lstlisting}[numbers=none,language={},basicstyle=\ttfamily\small]
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
    80
$ curl -L https://github.com/com-lihaoyi/Ammonite/releases/\
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
    81
  download/2.5.9/3.2-2.5.9 --output amm.bat
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
    82
\end{lstlisting} %% $  
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
    83
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
    84
\noindent
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
    85
Then you need to run Ammonite with \texttt{.$\backslash$amm} and there
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
    86
is no need to change any permissions under Windows.  
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
    87
759
d70dd0b57e35 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 756
diff changeset
    88
The big advantage of Ammonite is that it comes with some additional
d70dd0b57e35 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 756
diff changeset
    89
libraries already built-in and also allows one to easily break up code
d70dd0b57e35 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 756
diff changeset
    90
into smaller modules. For example reading and writing files in
d70dd0b57e35 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 756
diff changeset
    91
Ammonite can be achieved with
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    92
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    93
\begin{lstlisting}[numbers=none,language=Scala]
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    94
scala> import os._
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    95
scala> write.over(pwd / "file.name", "foo bar")  
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    96
scala> read(pwd / "file.name")   
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
    97
res1: String = "foo bar"
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    98
\end{lstlisting}
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    99
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   100
\noindent
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
   101
The second line writes the string \code{"foo bar"} into the file
759
d70dd0b57e35 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 756
diff changeset
   102
\code{"file.name"}, which is located in the current working
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
   103
directory (\code{pwd}). For loading and accessing code from
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
   104
another Scala file, you can import the code into Ammonite
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
   105
as follows:
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   106
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   107
\begin{lstlisting}[numbers=none,language=Scala]
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   108
import $file.name-of-the-file
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   109
import name-of-the-file._
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   110
\end{lstlisting}  %% $
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   111
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   112
\noindent
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   113
This assumes the other Scala file is called
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   114
\texttt{name-of-the-file.sc} and requires the file to be in the same
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   115
directory where \texttt{amm} is working in. This will be very convenient 
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   116
for the compiler we implement in CFL, because it allows us to easily
760
d41956ea544e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 759
diff changeset
   117
break up the code into the lexer, parser and code generator.
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   118
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
   119
Another handy feature of Ammonite is that you can mark functions as
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
   120
\texttt{@main}. For example
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   121
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   122
\begin{lstlisting}[numbers=none,language=Scala]
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   123
@main
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   124
def foo() = ...
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   125
\end{lstlisting}
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   126
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   127
\noindent
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   128
This means you can now call that function from the command line like
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   129
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   130
\begin{lstlisting}[numbers=none,language=Scala]
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   131
$ amm file.sc foo
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   132
\end{lstlisting} %% $
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   133
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   134
\noindent
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   135
If you want to specify an argument on the commandline, say an int and
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   136
a string, then you can write
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   137
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   138
\begin{lstlisting}[numbers=none,language=Scala]
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   139
@main
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   140
def bar(i: Int, s: String) = ...
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   141
\end{lstlisting}
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   142
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   143
\noindent
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   144
and then call
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   145
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   146
\begin{lstlisting}[numbers=none,language=Scala]
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   147
$ amm file.sc 42 foobar
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   148
\end{lstlisting} %% $
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   149
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   150
\noindent
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
   151
What is also good in Ammonite is that you can specify more than one
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   152
function to be ``main'' and then specify on the command line which
760
d41956ea544e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 759
diff changeset
   153
function you want to run as entry-point.
d41956ea544e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 759
diff changeset
   154
d41956ea544e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 759
diff changeset
   155
Another feature you might like to use is that Ammonite can ``watch'' files.
d41956ea544e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 759
diff changeset
   156
This means it can automatically re-run a file when it is saved. For this
d41956ea544e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 759
diff changeset
   157
you have to call \texttt{amm} with the option \texttt{-w}, as in
d41956ea544e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 759
diff changeset
   158
d41956ea544e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 759
diff changeset
   159
\begin{lstlisting}[numbers=none,language=Scala]
d41956ea544e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 759
diff changeset
   160
$ amm -w file.sc
d41956ea544e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 759
diff changeset
   161
\end{lstlisting} %% $
d41956ea544e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 759
diff changeset
   162
d41956ea544e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 759
diff changeset
   163
\noindent Of course this requires that you use \texttt{println} for
917
89e05a230d2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 870
diff changeset
   164
inspecting any data as otherwise nothing will be displayed at the
760
d41956ea544e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 759
diff changeset
   165
commandline.
924
6ad0f63e1968 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 917
diff changeset
   166
\smallskip
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   167
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   168
\noindent
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   169
To sum up, Ammonite is a really useful addition to the Scala ecosystem.
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   170
You can find more information about how to use it in the first five chapters
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   171
of the ``Hands-on Scala'' book by Li Haoyi. These chapters are
936
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
   172
free and can be used as a reference, see
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   173
936
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
   174
\begin{center}
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
   175
\url{https://www.handsonscala.com/part-i-introduction-to-scala.html}
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 924
diff changeset
   176
\end{center}
754
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   177
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   178
\end{document}
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   179
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   180
%%% Local Variables: 
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   181
%%% mode: latex
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   182
%%% TeX-master: t
1c9a23304b85 ammonite
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   183
%%% End: