NOTE: This guide is deprecated and will not be updated, as all Scala 2 code is migrated to Scala 3 in this repo.
- All code in [compendium/examples] has been migrated using
-rewrite
- All code in [compendium/workspace] has been migrated using
-rewrite
See issues and progress here: https://github.com/lunduniversity/introprog/issues
- Exercises - see instructions below
- Slides of lectures and text in compendium
- Discussion and decision on what new stuff to teach in Scala 3 in the second study period of the course, see general discussion here #509
Unfortunately there are neither .msi
files for Windows nor .deb
package for Linux, for Scala 3 on the download page. Instead you can do one or more of the following:
-
Use
sbt
with at leastsbt.version=1.5.5
inproject/build.properties
andscalaVersion := "3.0.1"
inbuild.sbt
and you can launch the REPL withsbt console
-
Use scala-runners.
-
Use Coursier according to here and then:
cs install scala3-compiler
andcs install scala3-repl
to getscala3-compiler
andscala3-repl
on your path -
Download the latest Scala 3 zip on github and make the binaries available on your path so you can write
scala
andscalac
in terminal.
Exercises are migrated manually (i.e. not using the Scala 3 compilers -rewrite
option) as they are snippets that should work in REPL that often do not compile on their own and they are embedded in the latex code.
Exercises are located here [compendium/modules] prefixed with week and suffixed with -exercise.tex
-
Study the syntactic differences between Scala 2 and Scala 3 here: https://docs.scala-lang.org/scala3/guides/migration/incompat-syntactic.html and the new coding style here: https://docs.scala-lang.org/scala3/guides/migration/tooling-syntax-rewriting.html
-
Fork this repo and clone it locally, etc.
-
Make sure you can
sbt build
with a working local Latex installation (e.g. TexLive, on linux/WSLsudo apt install texlive-full
) so that you getpdflatex
on your path -
Study how to make a contribution to this repo in Chapter 0 here on page 16 [http://cs.lth.se/pgk/compendium]
-
Locate the issue corresponding to the exercise you are migrating here called something like
Migrate exercise w01 expressions
-
Focus on fixing these most common cases first:
- Fix things that does not work anymore, e.g. calling
def f() = 42
with justf
does not work anymore - you need to match the parenthesis at definition site with the call site. - Use new control syntax:
if then
,for do
,for yield
,while do
- Make braces optional where sensible. One-liners can for space reasons or convenience still use braces.
- Avoid unnecessary braces in lambdas; this is legal in Scala 3:
table.map((k,v) => multiple line-breaks here)
- Fix things that does not work anymore, e.g. calling
-
Migrate both the task and the facit.
-
Remember to check everything in the Scala 3 REPL before you commit.
-
When you make a Pull Request on a fix to an exercises, then mention
fix #999
in the title of the PR message where#999
is replaced with the number of the corresponding migration issue. Then the issue will be automatically closed when the PR is merged.
In terminal on project top level run:
sh show-scala-versions.sh
- make
scala3-compiler
available on your path or as an alias - open a terminal in this repo's top folder
- run in terminal:
./rewrite-to-scala3.sh path/to/where/code/is/*.scala
- check that the rewriting looks ok
Start sbt in terminal on project top level and then:
sbt:introprog root> project w03_irritext
sbt:introprog root> set scalacOptions := Seq("-rewrite","-new-syntax")
sbt:introprog root> compile
sbt:introprog root> set scalacOptions := Seq("-rewrite","-indent")
sbt:introprog root> compile
It is important to rewrite to -new-syntax
before rewriting -indent
.
The rewritings can be reverted:
sbt:introprog root> set scalacOptions := Seq("-rewrite","-no-indent")
sbt:introprog root> compile
sbt:introprog root> set scalacOptions := Seq("-rewrite","-old-syntax")
sbt:introprog root> compile
It is important to revert to -no-indent
before reverting to -old-syntax
.