This page lists errata for the book Programming in Scala.
Discussions also appear on the Programming in Scala forum on artima.com.
As you find errors, first check here and the Suggest link off your copy of scalabook.pdf to see if it has already been reported. If not, first report it to the authors via the Suggest link on your PDF. Only then should you add errata here, in page order using level 4 headings so that the table of contents links to individual pages.
If an anonymous function consists of one statement that takes a single argument, you need not explicitly name and specify the argument.
In addition, if you omit the argument, you also must omit the right arrow.
new String("Hello, world!")
is a horrible example, one which should be expunged from the Java programmer’s lexicon and which should not be introduced to Scala programmers. It might be better to show creating an instance of MyClass from p. 29, or
val l = new java.util.ArrayList(100)
l.add("Hello, World!")
println(l)
It is incorrect to sat that Nil Creates an empty List. Nil evaluates to an empty list; subsequent references to Nil return the same empty list.
Similarly, List() does not create a new list each time; it returns the same value as Nil
The result of 1/2 * 3/5 is 3/10 not 3/15
... rational numbers do not have state should be ... rational numbers do not have mutable state
It will augmented ... should be It will be augmented ....
The example is missing the closing right brace }
In class Rational, g should be initialized as
private val g = gcd(n, d)
The four operators are not defined correctly: all incorrectly use this * new Rational(that), and each omitted the required return type.
The code should be
def + (that: Int): Rational = this + new Rational(that) def - (that: Int): Rational = this - new Rational(that) def * (that: Int): Rational = this * new Rational(that) def / (that: Int): Rational = this / new Rational(that)
It creates a source file from the file name
should be It creates a Source object from the file name
Following
For instance, say you mistook thedropmethod of lists fortail, so you forgot that you need to pass a number todrop.
the example should show println(drop)
What would have happened is that the expressionsqrtis treated as a function object
should be
What would have happened is that the expression drop is treated as a function object
def withPrintWriter(file: File)(operation: PrintWriter => Unit) {
should be
def withPrintWriter(f: File)(operation: PrintWriter => Unit) {
to match the use of f within this method, as well as the earlier example at the top of the page and on p 160.
lihe this should be like this
op ← opGroups(i).elements
should be
op ← opGroups(i)