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 back cover [2]
Change “Traits can't have constructors” to “Traits can't have constructor parameters”
Page 4 [2]
The cross-reference has extra text in the section title. It should be Section 1.1, “The Scala Interpreter”
Page 15 [2]
Change “Then it gets confused about else -1.” to “Then it gets confused about the else keyword.”
Page 16 [3]
Change “to separate r = r * x” to “to separate r = r * n
Page 17 [2]
The cross-reference has extra text in the section title. It should be Section 2.7, “Functions”
Page 17 [3]
Change “A block that ends with an assignment statement” to “A block that ends with an assignment”
Page 25 [2]
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 25 [3]
In the last code block, change var in to val in
Page 32 [2]
Change
for (elem <- a if a % 2 == 0) yield 2 * elem

to

for (elem <- a if elem % 2 == 0) yield 2 * elem
Page 33 [2]
Change “Given a sequence of integers” to “Given an array buffer of integers”
Page 33 [2]
After “First collect the indexes to keep:”, change var first = false to var first = true
Page 34 [2]
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 42 [2]
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 53 [2]
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.1 [2]
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 [2]
Change the cross-reference to “Section 5.2, Properties with Getters and Setters”
Page 66 [2]
The cross-reference has extra text in the section title. It should be Section 6.3, “Objects Extending a Class or Trait”
Page 66 Exercise 14
Change UnaryOperation<Color> to UnaryOperator<Color>.
Page 70 [2]

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

Page 81 [2]

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 [2]
Change var salary: 0.0 to var salary = 0.0
Page 86 [2]
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 [2]
Change public class Person to class Person
Page 87 [2]
Change public class Employee extends Person to class Employee extends Person
Page 93 [2]
Change
class Bug extends {
  override val range = 3

to

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

add

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

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

Page 191 [2]
Change head: B to head: E

Change unapply(result) to unapply(lst)

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

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

Page 215 [2]
Change “Section 16.2 shows all node types.” to “Figure 16-1 shows all node types”
Page 216 [3]
Change alt="San José State University Logo" to alt="San Jos&eacute; State University Logo"
Page 225 [2]
Change XML.save(writer, root, "UTF-8", false, null) to XML.write(writer, root, "UTF-8", false, null)
Page 234 [2]
In the Caution note at the top of the page, change “upper bound” to “lower bound” and indent the displayed code so that it doesn't bump against the icon.
Page 234 [2]
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 [2]
Change
T <: Upper >: Lower

to

T >: Lower <: Upper
Page 238 [2]
Change

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

to

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

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

to

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

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

Page 253 [2]
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 [2]
Change abstract trait to trait (2x)
Page 258 [2]
Change def read(in: In) to def read(in: In): Contents
Page 259 [2]
Change
trait ActionListener {

to

trait ActionListener extends Listener {
Page 262 [2]
Change
object ButtonModule extends ListenerSupport
{

to

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

to

class Buffer[E] extends Iterable[E] {
Page 272 [2]
In
((3~List())~Some((-~((4~List((*~5)))~None))))

the expression ((3~List()) should be in bold.

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

to

def ones: Parser[Any] = "1" ~ ones
Page 276 [3]
The change in the second printing was not right. It should have been
def ones: Parser[Any] = ones ~ "1" | "1"          
        
for the first code display on the page.
Page 294 [2]
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 [2]
Change val c = new Channel to val channel = new Channel (2x). Change case !(c, x) =>  to case !(channel, x) =>
Page 295 [2]
Change “by using the ?! operator” to “by using the !? operator”
Page 297 [2]
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 [2]
Change “you can change that behavior handler” to “you can change that behavior”
Page 303 [2]
Change javax.imageio.IOImage.read to javax.imageio.ImageIO.read
Page 310 [2]
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 [2]
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 311 [3]
Change “an implicit value of type Ordering[Int] in the Predef scope” to “an implicit value of type Ordering[Int] in the Ordering companion object”
Page 316 Exercise 3 [2]
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 [2]
Change Obtain to Read in
Page 323 [2]
Change
k: (String => String) => {
  "Exit"
}

to

k: (String => String) => "Exit"
Page 324 [2]
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 329/331 [3]
The (5) number inside the black circle on page 331 should actually be placed on page 329, after process(response1, response2) //
Page 331 [2]
Remove the line
    textField.setEnabled(false)

Thanks to Ari Meyer, Jason Blochowiak, Stephyn Butcher, Donna Converse, Charles David Crawford III, Sanjay Dasgupta, Rob Dickens, Stephen Eldridge, Ersin Er, Carey Evans, Dominik Gruntz, Matt Hurne, Edgard Kassab, Jessica Kerr, William King, Alina Kirsanova, Lex, Konstantin Milyutin, Vladimir Nikolaev, Marcello Presulli, Mike Shields, Alex Ignácio da Silva, Brad Smith, Daniel Sobral, Allan Todd, 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:
* =