By Developers, For Developers

Historical errata for Programming Scala

PDF PgPaper PgTypeDescriptionFixed onComments
26TYPO

When I try the following example:

scala> def isPalindrome(str: String) =
| str == str.reverse().toString()

I have the exception:
:4: error: wrong number of arguments for method apply: (Int)Char in class RichString
def isPalindrome(str: String) = str == str.reverse().toString()

I guess it should be:
def isPalindrome(str: String) = str == str.reverse.toString()

2009-04-03Thanks for the catch! Fixing it right away.
30TYPO

“On Windows, you’d set the classpath to the location of the Scala library.jar.
For example, on my Vista machine, I set it to C:\\programs\\scala\\scala-
2.7.3.final\\lib\\scala\\library.jar;.”

Last part should be scala-library.jar

2009-04-04Thanks for reporting. Fixing it right now.
8TYPO

“without begin bogged down” should be “without being bogged down”

2009-04-07
8TYPO

“Scala let’s you put all that power” should be “Scala lets you put all that power”

2009-04-07
9TYPO

“if you can’t change it’s content” should be “if you can’t change its content”

2009-04-07
9TYPO

“The benefits of Scala, however, is not limited” should be “The benefits of Scala, however, are not limited”

2009-04-07
10TYPO

“Furthermore, it’s syntax is” should be “Furthermore, its syntax is”

2009-04-07
10TYPO

“not one of the easiest syntax to work with” should be “not one of the easiest syntaxes to work with”, or — better — “not the easiest syntax to work with”

2009-04-07
12TYPO

“You loop though each of the symbol” should be “You
loop though each of the symbols”

2009-04-07
13TYPO

“the block in the context of next element.” should be “the block in the context of the next element.” But really, you’ve completely lost me in this paragraph. What does foldLeft do? I have no idea how one call to the block is somehow getting passed to another call to the block. Is there recursion going on here? If so, I don’t see where it happens. Am I really supposed to be able to “understand how this is working”?

2009-04-07Thanks for reporting the errors Peter. I will see what I can do to address the above issue.
14TYPO

“Since you only hand immutable state” should be “Since you only handle immutable state”?

2009-04-07
15TYPO

“the style you’re most comfortable within the scope” should be “the style you’re most comfortable with within the scope”

2009-04-07
37ERROR

The words “do for” in the triple-quoted string literals are colour-coded, both in the first and second example on the page.

2009-04-14The color coding of keywords takes effect in the entire code. I don't have control over this coloring.
58ERROR

The PDF document shows chapter “4.6 static in Scala” as “4-1static in Scala” in the PDF bookmarks (in Preview.app, this can be seen when the sidebar is visible). The expected bookmark name is “static in Scala”.

This happens everywhere where a keyword is the first word in the chapter title, e.g. “The 4-1Any type”, “More about 4-1Nothing”, “4-1Option Type”.

2009-04-14
18TYPO

“The output they product” should be “The output they produce”

2009-04-14
32TYPO

“The left of the arrow (<—)” should read “The left of the arrow (<-)”.

2009-04-14
39TYPO

References to scala.collections packages should be scala.collection. E.g. scala.collections.immutable actually is scala.collection.immutable.

2009-04-14
27ERROR

For Windows XP, I had to use this:

scala -e “println(\\”Hello \\" + args(0) + \\“, \\” + args(1))" Buddy “Welcome to Scala”

Otherwise I get the error “+ was unexpected at this time.”

2009-04-14
119TYPO

‘complicate patterns’ should be ‘complicated patterns’ in the paragraph before section 9.6

2009-04-14
22TYPO

Sec. 1.6 Last sentence should end: ‘are entirely mine’ vs ‘is entirely mine’

2009-05-19
34TYPO

3rd paragraph, ‘you can’t inadvertently changing the value’ should be ‘you can’t inadvertently change the value’

2009-05-19
34SUGGEST

You have the => symbol in the example but don’t provide any details (I know it’s later in the book). Just a little bit of explanation or at least mentioning it would be valuable.

2009-05-19
76TYPO

3rd paragraph: ‘and the context element’ ‘element’ should have font to match code example as carryOver does.

2009-05-19
80TYPO

3rd paragraph: ‘you can defined full functions’ should be ‘you can define full functions’

2009-05-19
132TYPO

Scala’s concurrency model depends on we honoring immutability. Scala
expects we to pass immutable objects as messages between actors.
=>
Scala’s concurrency model depends on us honoring immutability. Scala
expects us to pass immutable objects as messages between actors.

2009-05-19
158TYPO

We can use scala tool to run both Scala compiled code and code compiled using javac.
=>
We can use the scala tool to run both Scala compiled code and code compiled using javac.

2009-05-19
134TYPO

Jashua Bloch -> Joshua Bloch

2009-05-19
132SUGGEST

Add reference or footnote for command query-separation.

2009-05-19
30SUGGEST

The MIME type of the source code like the one for Script.scala (and the other scripts) should be text/plain instead of text/html. It is not correctly rendered by the browser. Just an idea.

2009-05-20
68TYPO

“Unfortunately, the way we’re used to is not a idiomatic way to define methods in Scala.”

It should be “an idiomatic way”. Notice the “an” vs. “a”.

132SUGGEST

Change the following sentence:

Scala’s concurrency model depends on we honoring immutability. Scala
expects we to pass immutable objects as messages between actors.

to:

Scala’s concurrency model depends on us to honor immutability. Scala
expects us to pass immutable objects as messages between actors.

2009-06-16
132TYPO

Jashua Bloch => Joshua Bloch

2009-06-16
81TYPO

However, in Scala, we can defined full functions within other functions. => we can define

2009-06-16
88TYPO

“instance given tous” -> “instance given to us”

90TYPO

“in the code previous” -> “in the previous code”

94SUGGEST

When testing the code examples I noticed that you have to be extra careful to leave an empty line after “def helpAsFriend(friend: Friend) = friend listen”, otherwise you have to use the format “friend.listen” or get error “wrong number of arguments for method listen: ()Unit”.

98TYPO

“val emplomentApplication” -> “val employmentApplication”

71TYPO

your where you is appropriate.
“But, your protest, the method is benign.”
probably should be…
“But, you protest, the method is benign.”

38ERROR

The text in chapter: Getting up to speed in Scala (excerpt), page #38, specifies, “So, calling 1 to 3 is equivalent to 1.to(3), but the former is more elegant”. Expression 1.to(3) should be expressed as (1).to(3), as Scala’s lexer uses longest match rule for tokens and in expression 1.to(3), 1. will be considered as 1.0, a Double rather than an Int.

84TYPO

The author forgot to include the “var” in front of the repeated “max” example statements. These lines will not execute as written but will after the var is added. JMH

def max2(a: Int, b: Int) : Int = if (a > b) a else b
var max = (Integer.MIN_VALUE /: arr) { (large, elem) => max2(large, elem) }
We are sending the pair of values (large and elem) to the max2( ) method
to determine which of those two is larger. We use the result of that
computation to eventually determine the largest element in the array.
Use the _ to simplify this:
max = (Integer.MIN_VALUE /: arr) { max2(,) }
The _ represents not only a single parameter; it can represent the entire
parameter list as well. So, we can modify the call to max2( ) as follows:
max = (Integer.MIN_VALUE /: arr) { max2 _ }
In the previous code, the _ represents the entire parameter list, that is,
(parameter1, parameter2). If you are merely passing what you receive to
an underlying method, you don’t even need the ceremony of the _. We
can further simplify the previous code:
max = (Integer.MIN_VALUE /: arr) { max2 }

49SUGGEST

It is not evident (at least not to me) that the Protected.scala examples cannot be run from the interpreter. Since this is the first time in the book this appears, it might get exaplined later, but at this page you have no idea why running with scala fails and only scalac shows the error you mention.

197ERROR

The Code example UsingScala/StockPriceFinder uses java.util.Date().getYear. This method on Date is deprecated and does not return the date in the expected format e.g. 2009 but as year-1900 i.e. 109.

This means that year call to the Yahoo webservice returns as much data as is available. E.g. for AAPL it returns around 15 years of data.

Suggestion would be to use Calendar instead.

111TYPO

‘plus the literal “done.”’ -> ‘plus the literal “done”.’
‘does not match “done,” then’ -> ‘does not match “done”, then’

118TYPO

“SYMBOL:PRICE.” -> “SYMBOL:PRICE”.

119TYPO

“SYMBOL:PRICE.” -> “SYMBOL:PRICE”.
A running gag ;-)

123TYPO

“GOOG,” -> “GOOG”,
The last for today

65ERROR

Footnote 4. reads: “Equivalent Java code will compile with no errors but result in a runtime ClassCastException.”

I think it is not true. Java equivalent will compile and run with no errors. E.g. following code runs without any problems.
List list1 = new ArrayList();
List list2 = new ArrayList();
list2 = list1;
\t\t
// this will execute successfully
list2.add(“2”);
System.out.println(list1);
System.out.println(list2);

111TYPO

The Scala alternate method for foldRight is actually :\\ and not \\: as written.

135TYPO

10.5: … about explicitly staring an actor…
should be
… about explicitly starting an actor…

139ERROR

You write, that if the TIMEOUT object is not pattern matched, an exception is thrown. I have tested this with Scala 2.8.0 and there no exception is thrown. The TIMEOUT object is simply stored in the mailbox, and if it is not pattern matched, then it remains in the mailbox and receiveWithin does not terminate after the specified period.

164TYPO

Text references java.util.AraryList instead of java.util.ArrayList

170ERROR

In the ExpectExample code snippet, the code comment states that “The above exception is wrong”, it seems that this should say “The above expectation is wrong”.

97TYPO

The employment application example creates a value with a name of “emplomentApplication”. There is a missing Y in this name.

141TYPO

explicitly staring an actor" should be "explicitly starting an actor

61ERROR

The code sample (SensibleTyping/Methods.scala) does not work as either a stand-alone script or when the code is transplanted to a class. In either scenario it throws a NoSuchMethodException.

52ERROR

Marker.scala does not compile on Scala 2.9.

:10: error: constructor Marker in class Marker cannot be accessed in object Marker
“red” -> new Marker(“red”),
^
:11: error: constructor Marker in class Marker cannot be accessed in object Marker
“blue” -> new Marker(“blue”),
^
:12: error: constructor Marker in class Marker cannot be accessed in object Marker
“green” -> new Marker(“green”)

40TYPO

The words “do for” in the code snippet is overstriked. Is that a typo?

64SUGGEST

It seems that in Generics.scala more is shown than is intended. I suspect that

var list1 : List[Int] = new ArrayList[Int]

was really meant to read

var list1 : ArrayList[Int] = new ArrayList[Int]

As written in the text, more than simple type inference is occurring in var list1 : List[Int] = new ArrayList[Int] — there is also casting. Consequently,

list2 = list1

will produce an error:

error: type mismatch;
found : java.util.List[Int]
required: java.util.ArrayList[Int]
list2 = list1
^
This does not negate the intent of the example, but it does obscure it a bit. In one sense, this example is even more instructive than intended.

69TYPO

The code for Methods.scala does not work as expected and produces runtime errors, at least with scala 2.9.1 and IcedTea7 2.0 on Ubuntu.

Specifically, every invocation of printMethodInfo gives something like this:

printMethodInfo(“method3”)
java.lang.NoSuchMethodException: .method3(null)
\tat java.lang.Class.getDeclaredMethod(Class.java:1954)
\tat .printMethodInfo(:9)
\tat .(:9)
\tat .()
\tat .(:11)
\tat .()
\tat $print()
\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
\tat java.lang.reflect.Method.invoke(Method.java:601)
\tat scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
\tat scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920)
\tat scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
\tat scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
\tat java.lang.Thread.run(Thread.java:722)

I have not tried this with any release of Sun/Oracle Java. And I have not tried this with IcedTea 6.

132ERROR

mailboxSize is never not 0. As I’m still learning Scala, I’m not quite able to figure out why from the source though given this book is now 4+ years old, things may have changes here.

141ERROR

“You can restart the actor, if you like, by calling the start( ) method.” - This is not possible.

16ERROR

the receiveWithin call inside getTopStock returns a RuntimeException.

See: issues.scala-lang.org/browse/SI-5460

Using: Scala version 2.10.2 (Java HotSpot™ 64-Bit Server VM, Java 1.7.0_40)

Categories: