- Concepts of Programming Languages

Scala Pragmatics

Instructor:

Learning Objectives

  • Set up a Scala development environment

Java and Scala

Using Scala

  • For real programs and homeworks, use sbt to run tests
  • File may only contain object and class declarations
    1. object o { val x = ... }
    2. class c { ... }
  • You can use console to get a REPL within sbt, use :quit to exit the REPL
  • In the sbt REPL, you can use import objects
    1. import o.*
    2. // use x

Using Scala

  • For tiny examples, type directly into the REPL
    1. val x = ...
    2. // use x
  • For larger examples, type in a file and :load into the REPL
    1. :load play/x.sc
    2. // use x
  • File contains declarations just as you would type them in the REPL
  • If there are expressions, then the last one is printed out as a value in the REPL
  • Do not put snippet files ending in .scala in the SBT directory; SBT expects object and class declarations and will report a compile error

Homework Assignments

  • Make sure you are in the right directory: run dir (Windows) or ls (Linux, MacOS) and check that the file build.sbt is listed
  • Compile the homework assignments: inside SBT compile or from command line sbt compile
  • Run all unit tests: inside SBT test or from command line sbt test
  • Run the tests of a single homework assignment: inside SBT testOnly fp1tests or from command line sbt "testOnly gameoflifetests"
  • Run the homework assignment tests whenever a file changes: inside SBT ~testOnly gameoflifetests
  • Run a single test of a single homework assignment: inside SBT testOnly gameoflifetests -- -n golex05