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
sbtwith at leastsbt.version=1.5.5inproject/build.propertiesandscalaVersion := "3.0.1"inbuild.sbtand you can launch the REPL withsbt console -
Use scala-runners.
-
Use Coursier according to here and then:
cs install scala3-compilerandcs install scala3-replto getscala3-compilerandscala3-replon your path -
Download the latest Scala 3 zip on github and make the binaries available on your path so you can write
scalaandscalacin 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 buildwith a working local Latex installation (e.g. TexLive, on linux/WSLsudo apt install texlive-full) so that you getpdflatexon your path -
Study how to make a contribution to this repo in Chapter 0 here on page 16 [http://fileadmin.cs.lth.se/pgk/compendium.pdf]
-
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() = 42with justfdoes 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 #999in the title of the PR message where#999is 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-compileravailable 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.