CIS 554 -- Scala Quiz 1 Name __________________________________

Please do not provide more than the question asks for. If I ask for a statement, don't put it in a function. If I ask for a function, don't put it in a class. If I ask to compute a value, don't print the result. And so on. I may or may not, at my discretion, mark such unnecessarily verbose answers as wrong.

  1. (1 point) Define numbers to be an immutable List of the integers 1 to 200, inclusive. Do not use a loop or recursion.

  2. (1 point) Define an immutable List someNums containing those numbers in numbers (from the previous question) that are either evenly divisible by 7, or whose last (rightmost) digit is a 3, or both. Do this with a filter, not with a loop or recursion.

  3. (1 point) Use a for-comprehension to define an immutable List someSquares containing the squares of the numbers in someNums (from the previous question).

  4. (1 point) Tell what the result will be of each of the following function calls:

    1. List(30, 75, 40, 85) find (_ > 50)

    2. List(30, 75, 40, 85) find (_ > 90)

  5. (1 point) Here is a complete class definition:
        class Noun(val text: String, var suffix: String, singular: Boolean)
    List the names of all the getters and setters that Scala automatically provides for objects of this class.

  6. (1 point) Write a match statement that uses the find function to find the first value in the list myList that is larger than 500, and either prints the value that was found, or prints "No such number."

  7. (3 points) Define:

    1. Referential transparency

    2. Uniform access principle

  8. (1 point) Given two lists of integers, list1 and list2, create a list of sums of the corresponding elements. For example, if list1 = List(10, 20, 30) and list2 = List(1, 2, 3, 4), produce the list List(11, 22, 33). You may use a for-comprehension, but no other kind of loop or recursion.

  9. (1 point) What is printed by the following sequence of expressions?

        var x = 3
        val y = 5
        val foo = (z: Int) => {
          val y = 11
          x + y + z
        x = 10