CIS 554 -- Scala Quiz 2 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) Complete the following sentence:

    A function is tail recursive if

  2. (1 point) What is the result of calling the following function with the argument 5? (Careful: Trick question!)

    def fiddle(n: Int) {
      (1 to n).toList map (1.0 / _)


  3. (1 point) Suppose you have the definition

    def area(width: Int)(height: Int) = width * height

    What is the type of this function? Please express your answer the same way the Scala REPL would.

  4. (1 point) Define atomic operation.

  5. (1 point) Define daemon thread.

  6. (1 point) By making a class into a case class, you get seven additional methods. Name three of them.

  7. (1 point) What is the result of this expression?   "abcde" ensuring (_.length > 3)

  8. (1 point) What is the result of this expression? List(1, 2, 3) flatMap(x => List(x, 4))

  9. (1 point) Distinguish between the Scala values Null and Nothing. (Notice the capitalization, it's important.)

  10. (1 point) Write an actor named yes_man that prints "I agree" when sent the message true, and exits when sent the message false.