equal
deleted
inserted
replaced
105 \definecolor{cellbackground}{HTML}{F7F7F7} |
105 \definecolor{cellbackground}{HTML}{F7F7F7} |
106 |
106 |
107 |
107 |
108 |
108 |
109 \begin{document} |
109 \begin{document} |
110 \fnote{\copyright{} Christian Urban, King's College London, 2017, 2018, 2019, 2020} |
110 \fnote{\copyright{} Christian Urban, King's College London, 2017, 2018, 2019, 2020, 2021} |
111 |
111 |
112 %\begin{tcolorbox}[breakable,size=fbox,boxrule=1pt,pad at break*=1mm,colback=cellbackground,colframe=cellborder] |
112 %\begin{tcolorbox}[breakable,size=fbox,boxrule=1pt,pad at break*=1mm,colback=cellbackground,colframe=cellborder] |
113 % abd |
113 % abd |
114 %\end{tcolorbox} |
114 %\end{tcolorbox} |
115 |
115 |
147 The official Scala compiler can be downloaded from |
147 The official Scala compiler can be downloaded from |
148 |
148 |
149 \begin{quote} |
149 \begin{quote} |
150 \url{http://www.scala-lang.org}\medskip |
150 \url{http://www.scala-lang.org}\medskip |
151 \end{quote} |
151 \end{quote} |
|
152 |
|
153 \noindent\alert |
|
154 Just make sure you are downloading the ``battle tested'' version of |
|
155 Scala \textbf{2.13} This is the one I am going to use in the lectures and |
|
156 in the coursework. The newer Scala 3.0 \& 3.1 still have some |
|
157 features not fully implemented.\bigskip |
152 |
158 |
153 \noindent |
159 \noindent |
154 If you are interested, there are also experimental backends of Scala |
160 If you are interested, there are also experimental backends of Scala |
155 for producing code under Android (\url{http://scala-android.org}); for |
161 for producing code under Android (\url{http://scala-android.org}); for |
156 generating JavaScript code (\url{https://www.scala-js.org}); and there |
162 generating JavaScript code (\url{https://www.scala-js.org}); and there |
1619 %\bigskip\noindent |
1625 %\bigskip\noindent |
1620 %\textit{More TBD.} |
1626 %\textit{More TBD.} |
1621 |
1627 |
1622 %\subsection*{Coursework} |
1628 %\subsection*{Coursework} |
1623 |
1629 |
1624 |
1630 \begin{figure}[p] |
1625 \subsection*{Scala Syntax for Java Developers} |
1631 \begin{boxedminipage}{\textwidth} |
1626 |
1632 \textbf{Scala Syntax for Java Developers}\bigskip |
|
1633 |
|
1634 \noindent |
1627 Scala compiles to the JVM, like the Java language. Because of this, |
1635 Scala compiles to the JVM, like the Java language. Because of this, |
1628 it can re-use many libraries. Here are a few hints how some Java code |
1636 it can re-use many libraries. Here are a few hints how some Java code |
1629 tranlsates to Scala code:\bigskip |
1637 tranlsates to Scala code:\bigskip |
1630 |
1638 |
1631 \noindent |
1639 \noindent |
1635 \end{lstlisting} |
1643 \end{lstlisting} |
1636 |
1644 |
1637 \begin{lstlisting}[language=Scala] |
1645 \begin{lstlisting}[language=Scala] |
1638 val coke : Drink = getCoke()/*!\annotation{Scala}!*/ |
1646 val coke : Drink = getCoke()/*!\annotation{Scala}!*/ |
1639 \end{lstlisting} |
1647 \end{lstlisting} |
|
1648 |
|
1649 \noindent |
|
1650 or even |
|
1651 |
|
1652 \begin{lstlisting}[language=Scala] |
|
1653 val coke = getCoke()/*!\annotation{Scala}!*/ |
|
1654 \end{lstlisting}\bigskip |
1640 |
1655 |
1641 \noindent |
1656 \noindent |
1642 Unit means void: |
1657 Unit means void: |
1643 |
1658 |
1644 \begin{lstlisting}[language=Java] |
1659 \begin{lstlisting}[language=Java] |
1647 } |
1662 } |
1648 \end{lstlisting} |
1663 \end{lstlisting} |
1649 |
1664 |
1650 \begin{lstlisting}[language=Scala] |
1665 \begin{lstlisting}[language=Scala] |
1651 def output(s: String): Unit = println(s)/*!\annotation{Scala}!*/ |
1666 def output(s: String): Unit = println(s)/*!\annotation{Scala}!*/ |
1652 \end{lstlisting} |
1667 \end{lstlisting}\bigskip |
1653 |
1668 |
1654 \noindent |
1669 \noindent |
1655 Type for list of Strings: |
1670 Type for list of Strings: |
1656 |
1671 |
1657 \begin{lstlisting}[language=Java] |
1672 \begin{lstlisting}[language=Java] |
1658 List<String>/*!\annotation{Java}!*/ |
1673 List<String>/*!\annotation{Java}!*/ |
1659 \end{lstlisting} |
1674 \end{lstlisting} |
1660 |
1675 |
1661 \begin{lstlisting}[language=Scala] |
1676 \begin{lstlisting}[language=Scala] |
1662 List[String]/*!\annotation{Scala}!*/ |
1677 List[String]/*!\annotation{Scala}!*/ |
1663 \end{lstlisting} |
1678 \end{lstlisting}\bigskip |
1664 |
1679 |
1665 \noindent |
1680 \noindent |
1666 String interpolations |
1681 String interpolations |
1667 |
1682 |
1668 \begin{lstlisting}[language=Java] |
1683 \begin{lstlisting}[language=Java] |
1670 /*!\annotation{Java}!*/ |
1685 /*!\annotation{Java}!*/ |
1671 \end{lstlisting} |
1686 \end{lstlisting} |
1672 |
1687 |
1673 \begin{lstlisting}[language=Scala] |
1688 \begin{lstlisting}[language=Scala] |
1674 println(s"Hello, $first $last!")/*!\annotation{Scala}!*/ |
1689 println(s"Hello, $first $last!")/*!\annotation{Scala}!*/ |
1675 \end{lstlisting} |
1690 \end{lstlisting}\bigskip |
1676 |
1691 |
1677 \noindent |
1692 \noindent |
1678 Java provides syntactic some sugar when constructing anonymous functions: |
1693 Java provides some syntactic sugar when constructing anonymous functions: |
1679 |
1694 |
1680 \begin{lstlisting}[language=Java] |
1695 \begin{lstlisting}[language=Java] |
1681 list.foreach(item -> System.out.println("* " + item)); |
1696 list.foreach(item -> System.out.println("* " + item)); |
1682 /*!\annotation{Java}!*/ |
1697 /*!\annotation{Java}!*/ |
1683 \end{lstlisting} |
1698 \end{lstlisting} |
1686 In Scala, we use the \code{=>} symbol: |
1701 In Scala, we use the \code{=>} symbol: |
1687 |
1702 |
1688 \begin{lstlisting}[language=Scala] |
1703 \begin{lstlisting}[language=Scala] |
1689 list.foreach(item => println(s"* $item"))/*!\annotation{Scala}!*/ |
1704 list.foreach(item => println(s"* $item"))/*!\annotation{Scala}!*/ |
1690 \end{lstlisting}%$ |
1705 \end{lstlisting}%$ |
|
1706 \end{boxedminipage} |
|
1707 \end{figure} |
1691 |
1708 |
1692 %%new / vs case classes |
1709 %%new / vs case classes |
1693 |
1710 |
1694 |
1711 |
1695 \subsection*{More Info} |
1712 \subsection*{More Info} |