wsheets/wsh01.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Thu, 10 Nov 2022 20:10:20 +0000
changeset 443 80c691a4caab
parent 442 c86e7dd198bf
child 444 7a0735db4788
permissions -rw-r--r--
updated

% !TEX program = xelatex
\documentclass{article}
\usepackage{../styles/style}
\usepackage{../styles/langs}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{marvosym}
\usepackage{boxedminipage}

\lstset{escapeinside={/*!}{!*/}}
\newcommand{\annotation}[1]{\hfill\footnotesize{}#1}

\usepackage{menukeys}


% Exact colors from NB
\usepackage[breakable]{tcolorbox}
\definecolor{incolor}{HTML}{303F9F}
\definecolor{outcolor}{HTML}{D84315}
\definecolor{cellborder}{HTML}{CFCFCF}
\definecolor{cellbackground}{HTML}{F7F7F7}


    
\begin{document}
\fnote{\copyright{} Christian Urban, King's College London, 2022}

\section*{Scala Worksheet 1}

Please install Scala on your work-machine: You should have
Scala up and running, and also an IDE that allows you to
access the Scala REPL. Some instructions are given at

\begin{center}
\url{https://www.scala-lang.org/download/2.13.10.html}
\end{center}  

\subsubsection*{MacOSX}

\begin{itemize}
\item[0)] (if needed) \texttt{brew install java} \;\;or\;\; \texttt{brew reinstall java}
\item[1)] \texttt{brew install scala@2.13}
\end{itemize}

\noindent Another method to install Scala on MacOSX

\begin{itemize} 
\item[1)] \texttt{curl -s "https://get.sdkman.io" | bash}
\item[2)] \texttt{sdk install scala 2.13.10}  
\end{itemize}

\subsubsection*{Windows / Linux Ubuntu}

\begin{itemize}
\item[0)] (if needed) \texttt{sudo apt-get remove scala-library scala}
\item[1)] {\fontsize{8.5}{8.5}\selectfont\texttt{sudo wget https://downloads.lightbend.com/scala/2.13.10/scala-2.13.7.deb}}
\item[2)] \texttt{sudo dpkg -i scala-2.13.10.deb}  
\end{itemize}

\noindent
Other Linux distros: \texttt{sudo apt-get scala}\bigskip

\noindent In the end you should have something running like

\begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
$ scala
Welcome to Scala 2.13.10 (OpenJDK 64-Bit Server VM, Java 17.0.1).
Type in expressions for evaluation. Or try :help.

scala>
\end{lstlisting}%$

\newpage

\subsection*{Task 1}

`Play' with the Scala REPL and try out the following querries. Observe
what Scala responds.

\begin{lstlisting}[numbers=none]
scala> 2 + 2
scala> 1 / 2
scala> 1.0 / 2
scala> 1 / 2.0
scala> 1 / 0
scala> 1.0 / 0.0
scala> true == false
scala> true && false
scala> 1 > 1.0
scala> "12345".length
scala> List(1,2,1).size
scala> Set(1,2,1).size
scala> List(1) == List(1)
scala> Set(1,2,3) == Set(3,2,1)
scala> Array(1) == Array(1)
scala> Array(1).sameElements(Array(1))
\end{lstlisting}

\subsection*{Task 2 (Vals)}

scala> val z = 42
scala> z = z + 1
scala> val z = 466

\subsection*{Task 3}

\begin{lstlisting}[numbers=none]
scala> println("Hello " ++ "World")
scala> 
\end{lstlisting}

\begin{lstlisting}[numbers=none]
scala> println("Hello " ++ "World")
scala> 
\end{lstlisting}

\end{document}

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: