- Prerequisites
- Download
- Directory Structure
- Restrictions
- Exceptions
- Testing Your Implementation
- Submission
- Grading
This is a repository for assignment documents of courses by the Programming Languages Research Group (PLRG) at Korea University.
- Basics
- scala-tutorial - Scala Tutorial
- JDK >= 8 (https://www.oracle.com/java/technologies/downloads/)
- sbt (https://www.scala-sbt.org/download.html)
Run sbt new ku-plrg-classroom/[assignment name].g8 in your terminal.
The project directory whose name is the same as the assignment will be created
under the current directory.
⚠️ You should REPLACE[assignment name]with the name of the assignment or copy and paste the command from the document of each assignment.
Below is an example.
sbt new ku-plrg-classroom/scala-tutorial.g8
...
name [Scala Tutorial]:
⚠️ Please typeEnterkey if you want to use the default directory name.
You can find the following directories and files in the project directory:
src
├─ main/scala/kuplrg
│ ├─ Implementation.scala ─── SUBMIT THIS FILE
│ └─ Template.scala
└─ test/scala/kuplrg
├─ Spec.scala ───────────── ADD YOUR OWN TESTS
└─ SpecBase.scala
DO NOT edit files other than
src/main/scala/kuplrg/Implementation.scala and
src/test/scala/kuplrg/Spec.scala.
-
src/main/scala/kuplrg/Implementation.scala: You must fill this file to implement the required function(s). It is enough to edit only this file to finish the assignment. -
src/main/scala/kuplrg/Template.scala: This file contains the definitions of functions that you must implement to complete the assignment. Please DO NOT edit this file. -
src/main/scala/kuplrg/error.scala: This file defineserrorfunctions. Please refer to the Exceptions section for more details. -
src/test/scala/kuplrg/Spec.scalaThis file contains test cases. Please refer to the Writing Test Cases and Running Test Cases sections to learn how to write and run your own test cases. -
src/test/scala/kuplrg/SpecBase.scalaThis file contains a basic framework for test cases. You do not need to read or edit this file.
You MUST NOT use any of the following features in your implementation:
varwhileasInstanceOfisInstanceOfnullreturnthrowtry-catch- mutable data structures (in
scala.collection.mutable)
You can use any other features that are not explicitly forbidden. For example,
- You can define helper functions and additional types.
- You can use immutable data structures.
- You can use
forcomprehensions. - You can mutate mutable variables/fields already defined in the provided code.
The use of the prohibited features will make your code not compile. If your code compiles successfully, you are not using any prohibited features.
While you cannot use throw and try-catch in your implementation, you can
throw an exception with an error message s by calling error(s) defined in
Template.scala. The exception will be of a type PLError defined in
Template.scala. To omit the message, you can use error(), instead of
error("").
error() // throws a `PLError` with the message ""
error("foo") // throws a `PLError` with the message "foo"
def f(x: Int): Int =
if (x < 0) error("x must be non-negative")
else x
f(42) // 42
f(-1) // throws a `PLError` with the message "x must be non-negative"You can test PLError exceptions by using testExc. Please refer to the
Writing Test Cases section for more details.
You can write your own test cases in Spec.scala. You can use the test and
testExc functions to test your implementation.
def f(x: Int): Int =
if (x < 0) error("x must be non-negative")
else x
// test f(3) == 3
test(f(3), 3)
// test f(-1) throws a `PLError` with the message containing "non-negative"
testExc(f(-1), "non-negative")
⚠️ Passing all the provided tests does not guarantee that your implementation is correct. So, we HIGHLY RECOMMEND adding your own tests to check your implementation.
Under the project directory, execute sbt to start an sbt console.
$ sbt
[info] welcome to sbt
...
sbt:...>
To run the test cases in Spec.scala, execute the test command.
Every test case will fail at the beginning.
sbt:...> test
...
[error] Failed tests:
[error] kuplrg.Spec
After implementing every function correctly, every test will succeed.
sbt:...> test
...
[info] All tests passed.
If you want to watch the test results in real time, you can use the ~test.
Then, sbt will run the test cases every time you save the file.
If you want to test your implementation interactively, you can use the console
command in sbt. It will start a Scala REPL with the project. You can use any
variables and functions defined in Implementation.scala.
sbt:...> console
...
scala> import kuplrg.Implementation.*
scala> ...
Please use Blackboard to submit your code.
You must submit your Implementation.scala of each project.
⚠️ If you copy and paste existing code, you will get an F. You must work on each project by yourself without getting any help. You can refer to the lecture materials, including the lecture slides, or even other materials on the Internet. However, you should be able to explain the details of your code. If not, you will get an F.
We disallow late submissions. If you submit multiple times, only the last submission will be graded.
You can get maximum of 100 points. If your code uses a disallowed feature or does not compile, you will get 0 points.
The test cases for the grading are similar to, but not the same as, those
provided in Spec.scala. You get more points as you pass more test cases. The
execution of each test case does not affect the others, e.g., the other test
cases will be graded properly even when your implementation runs forever for a
certain test case.