178 number does not matter. Note that this will be the first year I am |
178 number does not matter. Note that this will be the first year I am |
179 using this newer version -- so some hiccups are bound to happen. Apologies |
179 using this newer version -- so some hiccups are bound to happen. Apologies |
180 in advance!\bigskip |
180 in advance!\bigskip |
181 |
181 |
182 \begin{tcolorbox}[colback=red!5!white,colframe=red!75!black] |
182 \begin{tcolorbox}[colback=red!5!white,colframe=red!75!black] |
183 I will be using the \textbf{\texttt{scala-cli}} REPL for scala, rather |
183 I will be using the \textbf{\texttt{scala-cli}} REPL for Scala 3, rather |
184 than the ``plain'' Scala REPL. This is a batteries included version of |
184 than the ``plain'' Scala REPL. This is a batteries included version of |
185 Scala and is easier to use. In fact \texttt{scala-cli} will replace |
185 Scala 3 and is easier to use and install. In fact |
186 the ``plain'' Scala REPL in future versions. So why not using it now? |
186 \texttt{scala-cli} is designated to replace |
|
187 the ``plain'' Scala REPL in future versions of Scala. |
|
188 So why not using it now? |
187 It can be downloaded from: |
189 It can be downloaded from: |
188 |
190 |
189 \begin{center} |
191 \begin{center} |
190 \url{https://scala-cli.virtuslab.org} |
192 \url{https://scala-cli.virtuslab.org} |
191 \end{center} |
193 \end{center} |
192 \end{tcolorbox}\medskip |
194 \end{tcolorbox}\medskip |
193 |
195 |
194 |
196 |
195 \noindent |
197 \noindent |
196 If you are interested, there are also experimental backend of Scala |
198 If you are interested, there are also experimental backends of Scala |
197 for generating JavaScript code (\url{https://www.scala-js.org}), and |
199 for generating JavaScript code (\url{https://www.scala-js.org}), and |
198 there is work under way to have a native Scala compiler generating |
200 there is work under way to have a native Scala compiler generating |
199 X86-code (\url{http://www.scala-native.org}). There are also some |
201 X86-code (\url{http://www.scala-native.org}). There are also some |
200 tricks you can play with Scala programms running as native |
202 tricks for Scala programs to run as a native |
201 GraalVM~\hr{https://scala-cli.virtuslab.org/docs/cookbooks/native-images/} |
203 GraalVM~\hr{https://scala-cli.virtuslab.org/docs/cookbooks/native-images/} |
202 images. Though be warned these backends are still rather beta or even |
204 image. Though be warned these backends are still rather beta or even |
203 alpha. |
205 alpha. |
204 |
206 |
205 \subsection*{VS Code and Scala} |
207 \subsection*{VS Code and Scala} |
206 |
208 |
207 I found a convenient IDE for writing Scala programs is Microsoft's |
209 I found a convenient IDE for writing Scala programs is Microsoft's |
239 terminal to run \texttt{scala-cli} version 1.0.5 which |
241 terminal to run \texttt{scala-cli} version 1.0.5 which |
240 uses Scala 3.3.1.\label{vscode}} |
242 uses Scala 3.3.1.\label{vscode}} |
241 \end{boxedminipage} |
243 \end{boxedminipage} |
242 \end{figure} |
244 \end{figure} |
243 |
245 |
244 Actually \alert last year I switched to VS Codium, which is VS Code |
246 Actually \alert last year I switched to VS Codium as IDE for writing Scala programs. VS Codium is VS Code |
245 minus all the telemetry that is normally sent to Microsoft. Apart from |
247 minus all the telemetry that is normally sent to Microsoft. Apart from |
246 the telemetry (and Copilot, which you are not supposed to use anyway), |
248 the telemetry (and Copilot, which you are not supposed to use anyway), |
247 it works pretty much the same way as the original but is driven by a |
249 it works pretty much the same way as the original but is driven by a |
248 dedicated community, rather than a big company. You can download VS |
250 dedicated community, rather than a big company. You can download VS |
249 Codium from |
251 Codium from |
252 \url{https://vscodium.com} |
254 \url{https://vscodium.com} |
253 \end{quote} |
255 \end{quote} |
254 |
256 |
255 |
257 |
256 What I like most about VS Code/Codium is that it provides easy access |
258 What I like most about VS Code/Codium is that it provides easy access |
257 to the Scala REPL. But if you prefer another editor for coding, it is |
259 to any Scala REPL. But if you prefer another editor for coding, it is |
258 also painless to work with Scala completely on the command line (as |
260 also painless to work with Scala completely on the command line (as |
259 you might have done with \texttt{g++} in the earlier part of PEP). For |
261 you might have done with \texttt{g++} in the earlier part of PEP). For |
260 the lazybones among us, there are even online editors and environments |
262 the lazybones among us, there are even online editors and environments |
261 for developing and running Scala programs: \textit{Scastie} and |
263 for developing and running Scala programs: \textit{Scastie} and |
262 \textit{ScalaFiddle} are two of them. They require zero setup |
264 \textit{ScalaFiddle} are two of them. They require zero setup |
503 \url{https://archive.ph/vrofC} |
505 \url{https://archive.ph/vrofC} |
504 \end{quote} |
506 \end{quote} |
505 |
507 |
506 \subsection*{The Very Basics} |
508 \subsection*{The Very Basics} |
507 |
509 |
508 Let us get back to Scala: One advantage of Scala over Java is that it |
510 Let us get back to Scala and \texttt{scala-cli}: One advantage of |
509 includes an interpreter (a REPL, or |
511 Scala over Java is that it includes an interpreter (a REPL, or |
510 \underline{R}ead-\underline{E}val-\underline{P}rint-\underline{L}oop) |
512 \underline{R}ead-\underline{E}val-\underline{P}rint-\underline{L}oop) |
511 with which you can run and test small code snippets without the need |
513 with which you can run and test small code snippets without the need |
512 of a compiler. This helps a lot with interactively developing |
514 of a compiler. This helps a lot with interactively developing |
513 programs. It is my preferred way of writing small Scala programs. Once |
515 programs. It is my preferred way of writing small Scala programs. Once |
514 you installed Scala, you can start the interpreter by typing on the |
516 you installed \texttt{scala-cli}, you can start the interpreter by typing on the |
515 command line: |
517 command line: |
516 |
518 |
517 \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small] |
519 \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small] |
518 $ scala-cli |
520 $ scala-cli |
519 Welcome to Scala 3.3.1 (17.0.8.1, Java OpenJDK 64-Bit Server VM). |
521 Welcome to Scala 3.3.1 (17.0.8.1, Java OpenJDK 64-Bit Server VM). |
520 Type in expressions for evaluation. Or try :help. |
522 Type in expressions for evaluation. Or try :help. |
521 |
523 |
522 scala> |
524 scala> |
523 \end{lstlisting}%$ |
525 \end{lstlisting}%$ |
524 |
526 |
525 \noindent The precise response may vary depending |
527 \noindent The precise response may vary depending on the version and |
526 on the version and platform where you installed Scala. Make sure |
528 platform where you installed \texttt{scala-cli}. Make sure however that |
527 \texttt{scala-cli} uses Scala version 3. At the Scala |
529 \texttt{scala-cli} uses Scala version 3---you can find the version |
528 prompt you can type things like \code{2 + 3}\;\keys{Ret} and |
530 number in the welcome message. Also note that at the first time |
529 the output will be |
531 \texttt{scala-cli} runs, it might download various components, for |
|
532 example the Scala compiler, Scala runtimes etc. Once |
|
533 \texttt{scala-cli} is up and running, you can type at the prompt |
|
534 expressions like \code{2 + 3}\;\keys{Ret} and the output will be |
530 |
535 |
531 \begin{lstlisting}[numbers=none,language={}] |
536 \begin{lstlisting}[numbers=none,language={}] |
532 scala> 2 + 3 |
537 scala> 2 + 3 |
533 val res0: Int = 5 |
538 val res0: Int = 5 |
534 \end{lstlisting} |
539 \end{lstlisting} |