Scala for the Impatient

Bug Report Page

.

How to Tell which Printing You Have

On the bottom of the copyright page (facing the first page of the table of contents), look for a line such as
First printing, March 2012

In the errata below, we indicate the printing in which the error has been fixed inside square brackets such as [4].

For example, suppose you have the fourth printing. Then you can ignore all reports that are prefixed with [2], [3] or [4]. But you would want to pay attention to all reports that are prefixed with [5] or higher or that have no bracketed prefix at all.

Inside cover
Change “Traits can't have constructors” to “Traits can't have constructor parameters”
Page 4
The cross-reference has extra text in the section title. It should be Section 1.1, “The Scala Interpreter”
Page 15
Change “Then it gets confused about else -1.” to “Then it gets confused about the else keyword.”
Page 17
The cross-reference has extra text in the section title. It should be Section 2.7, “Functions”
Page 25
Change the second code block to
val url = new URL("http://horstmann.com/fred-tiny.gif")
try {
  process(url)
} catch {
  case _: MalformedURLException => println("Bad URL: " + url)
  case ex: IOException => ex.printStackTrace()
}
Page 32
Change
for (elem <- a if a % 2 == 0) yield 2 * elem

to

for (elem <- a if elem % 2 == 0) yield 2 * elem
Page 33
Change “Given a sequence of integers” to “Given an array buffer of integers”
Page 33
After “First collect the indexes to keep:”, change var first = false to var first = true
Page 34
Change
val bSorted = b.sorted(_ < _)
   // b is unchanged; bSorted is ArrayBuffer(1, 2, 7, 9)

to

val bSorted = b.sorted // b is unchanged; bSorted is ArrayBuffer(1, 2, 7, 9)

Change “You pass the comparison function as a parameter—see Chapter 12 for the function syntax.” to

You can also supply a comparison function, but then you use the sortWith method:

val bDescending = b.sortWith(_ > _) // ArrayBuffer(9, 7, 2, 1)

See Chapter 12 for the function syntax.

Page 44
Change

If you want to start out with a blank map, you have to pick a map implementation and supply type parameters:

val scores = new scala.collection.mutable.HashMap[String, Int]

to

If you want to start out with a blank map, you have to supply type parameters:

val scores = scala.collection.mutable.Map[String, Int]()
Page 63 Exercise 5.1
The cross-reference has extra text in the section title. It should be Section 5.1, “Simple Classes and Parameterless Methods”
Page 63 Exercise 5.6
Change the cross-reference to “Section 5.2, Properties with Getters and Setters”
Page 66
The cross-reference has extra text in the section title. It should be Section 6.3, “Objects Extending a Class or Trait”
Page 70

Remove the / from “If that gets too tedious, use a statement /”

Page 81

Change “next = previous × a + b mod 2n” to “next = (previous × a + b) mod 2n”. Change “ and n = 32.” to “n = 32, and the inital value of previous is seed.”

Page 85
Change var salary: 0.0 to var salary = 0.0
Page 86
Change “Unlike Java, you” to “You”. After “(See Section 8.6, “Overriding Fields,” on page 89 for overriding fields.)” add “Note that this is different from Java, where a final field is immutable, similar to val in Scala.
Page 86
Change public class Person to class Person
Page 87
Change public class Employee extends Person to class Employee extends Person
Page 93
Change
class Bug extends {
  override val range = 3

to

class Ant extends {
  override val range = 2
Page 96
Below
private var balance = initialBalance

add

def currentBalance = balance
Page 119
In the figure, change max to maxLength
Page 126
Add a space before the { in public interface ShortLogger extends Logger {
Page 127
Change “Provide a CryptoLogger class” to “Provide a CryptoLogger trait”
Page 132
Remove $ from !#$%&*+-/:<=>?@\^|~
Page 135
Change “If f is is not a function” to “If f is not a function”
Page 139 Exercise 11.3
Change “turning 15/-6 into -5/3” to “turning 15/-6 into -5/2”
Page 158
In the figure, change Iterable to Seq
Page 179

Change “The tupled method of the Function2 class” to “The tupled method of the Function object”

Page 191
Change head: B to head: E

Change unapply(result) to unapply(lst)

Page 196 Exercise 14.1
Change alls? thr to [Ff]alls? thr
Page 196 Exercise 14.4
Change Product to Article
Page 197 Exercise 14.10
Change sqrt(Double) to sqrt(x)
Page 210
Change Comparable[Student] to Comparator[Student]
Page 211
Change Comparable to Comparator (2x)
Page 214

Change “Section 16.2 shows the complete hierarchy.” to “Figure 16-1 shows the complete hierarchy.”

Page 215
Change “Section 16.2 shows all node types.” to “Figure 16-1 shows all node types”
Page 225
Change XML.save(writer, root, "UTF-8", false, null) to XML.write(writer, root, "UTF-8", false, null)
Page 234
Change

It requires that there is an “implicit value” of type T[M].

to

It requires that there is an “implicit value” of type M[T].

Page 235
Change
T <: Upper >: Lower

to

T >: Lower <: Upper
Page 238
Change

// You can write the second parameter as find: Person => Person

to

// You can write the second parameter as find: Student => Person

Page 239
Change foldLeft[B](z: B)(op: (A, B) => B): B to foldLeft[B](z: B)(op: (B, A) => B): B
Page 241
Change
void makeFriends(Pair<? extends Person> people)

to

void makeFriends(List<? extends Person> people)
Page 242 Exercise 17.9
Change “in a Pair[T]” to “in a Pair[+T].”
Page 246
Change “Given any value v” to “Given any reference v”
Page 246
Change “a method that takes an Object instance as parameter” to ““a method that takes an object instance as parameter”
Page 250
Change “For example, this method has a structural type parameter: x” to “For example, this method has a structural type parameter: target
Page 250

Change “where T1, T1, T1, and so on are types” to “where T1, T2, T3, and so on are types”

Page 253
Change “because a val can have its own subtypes (see Section 18.1, “Singleton Types,” on page 246)” to “because a val can have its own nested types (see Section 18.2, “Type Projections,” on page 247)”
Page 257
Change abstract trait to trait (2x)
Page 258
Change def read(in: In) to def read(in: In): Contents
Page 259
Change
trait ActionListener {

to

trait ActionListener extends Listener {
Page 262
Change
object ButtonModule extends ListenerSupport
{

to

object ButtonModule extends ListenerSupport {
Page 263
Change
class Buffer[E] extends Iterable[E]

to

class Buffer[E] extends Iterable[E] {
Page 273
Change “because there are no * or /” to “because there is no *
Page 276
Change
def ones: Parser[Any] = "1" ~ rep("1")

to

def ones: Parser[Any] = "1" ~ ones
Page 294
Change
case class Compute(input: Seq[Int], result: OutputChannel[Int])
  class Computer extends Actor {
  while (true) {
    receive {
      case Compute(input, out) => { val answer = ...; out ! answer }
    }
  }
}

to

case class Compute(input: Seq[Int], result: OutputChannel[Int])
class Computer extends Actor {
  public void act() {
    while (true) {
      receive {
        case Compute(input, out) => { val answer = ...; out ! answer }
      }
    }
  }
}
Page 294/295
Change val c = new Channel to val channel = new Channel (2x). Change case !(c, x) =>  to case !(channel, x) =>
Page 295
Change “by using the ?! operator” to “by using the !? operator”
Page 297
Change “The partial function associated with react never returns a value” to “ “The partial function associated with the first react never returns a value””
Page 300
Change “you can change that behavior handler” to “you can change that behavior”
Page 303
Change javax.imageio.IOImage.read to javax.imageio.ImageIO.read
Page 310
Change “There can only be one implicit val for a given data type.” to “There can only be one implicit value for a given data type.”
Page 311
Change “It requires that there is an implicit value of type T[M] in scope.” to “It requires that there is an implicit value of type M[T] in scope.”
Page 316 Exercise 3
Change the exercise to  “Define a ! operator that computes the factorial of an integer. For example, 5! is 120. You will need an enrichment class and an implicit conversion.”
Page 316 Exercise 4
Change Obtain to Read in
Page 323
Change
k: (String => String) => {
  "Exit"
}

to

k: (String => String) => "Exit"
Page 324
Change
shift {
  k: (Unit => Unit) => { // A and B are Unit
    "Exit" // C is String
  } // Shift hole is Unit
}

to

shift {
  k: (Unit => Unit) => // A and B are Unit
    "Exit" // C is String
} // Shift hole is Unit
Page 331
Remove the line
    textField.setEnabled(false)
      

Thanks to Ari Meyer, Jason Blochowiak, Stephyn Butcher, Rob Dickens, Stephen Eldridge, Ersin Er, Dominik Gruntz, Matt Hurne, Edgard Kassab, Jessica Kerr, William King, Alina Kirsanova, Konstantin Milyutin, Vladimir Nikolaev, Marcello Presulli, Alex Ignácio da Silva, Brad Smith, Daniel Sobral, Romain Tribes, Philip Watson, Tyler Weir, Akim Zadeh, Kefu Zhou, Gerhard Zorn, and (your name might go here) for their bug reports and suggestions!

Bug Report Form

Please use this form to report any bugs that you find. Please check the list of known bugs first before you report a bug. Unfortunately, I do not have the time to respond personally to every report, but I do read them all and will post updates to this page. Thank you!

Your name:

Your email address:

Page number:

Problem description:

To protect against spam robots, please answer this simple math problem:
* =