- ISBN13: 978-1-4302-1989-7
- ISBN10: 1-4302-1989-0
- 350 pp.
- Published May 2009
- Print Book Price: $39.99
- eBook Price: $27.99
Errata Submission
If you think that you've found an error in Beginning Scala, please let us know about it. You will find any confirmed erratum below, so you can check if your concern has already been addressed.
Errata
| Issue | Author's Response |
|---|---|
| chapter 2, page 47, reads: Scala’s functions are anonymous inner classes. shouldn't it read: Scala’s functions are instances of anonymous inner classes. ? |
The functions are classes. Instances of the functions are instances of classes. |
| chapter 7, page 175, reads could get very old but should read could get very odd |
It reads correctly. "could get very old" is an idiomatic expression meaning that it could become very tiresome. |
| Chapter 4, page 94, reads The w42 method applies 42 to the function but should read The w42 method applies the function to 42 |
It reads correctly. |
| **I suspect this isn't erratum but I still be most grateful if you would look at it. Otherwise I would have to post on a help forum and I wouldn't want to post your book code in a blanket form (copyright etc)so I've come to you** Hello, I've just run Sum.scala from chap2, p16. I get errors, so I downloaded the source code to check it wasn't my typo. ive saved this as Sum22.scala to differentiate it from my copy (Sum.scala). In both cases, I get Microsoft Windows [Version 6.0.6002] Copyright (c) 2006 Microsoft Corporation. All rights reserved. C:\Users\Ruth>cd C:\Users\Ruth C:\Users\Ruth>cd "Scala Scripts" C:\Users\Ruth\Scala Scripts>scala Sum22.scala Enter some numbers and press ctrl-D (Unix/Mac) ctrl-C (Windows) 1 2 3 4 java.lang.NoClassDefFoundError: Main$$anon$1$$anonfun$sum$1 at Main$$anon$1.sum((virtual file):16) at Main$$anon$1.<init>((virtual file):25) at Main$.main((virtual file):4) at Main.main((virtual file)) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at scala.tools.nsc.ObjectRunner$$anonfun$run$1.apply(ObjectRunner.scala: 75) at scala.tools.nsc.ObjectRunner$.withContextClassLoader(ObjectRunner.sca la:49) at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:74) at scala.tools.nsc.ScriptRunner$.scala$tools$nsc$ScriptRunner$$runCompil ed(ScriptRunner.scala:381) at scala.tools.nsc.ScriptRunner$$anonfun$runScript$1.apply(ScriptRunner. scala:414) at scala.tools.nsc.ScriptRunner$$anonfun$runScript$1.apply(ScriptRunner. scala:413) at scala.tools.nsc.ScriptRunner$.withCompiledScript(ScriptRunner.scala:3 51) at scala.tools.nsc.ScriptRunner$.runScript(ScriptRunner.scala:413) at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:168) at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) Caused by: java.lang.ClassNotFoundException: Main$$anon$1$$anonfun$sum$1 at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) ... 18 more Terminate batch job (Y/N)? y C:\Users\Ruth\Scala Scripts> I suspect this may be a Windows Vista thing but I'm still a beginner and you may recognise it, and I would be really grateful if you could share you knowlege. I entered the number, then enter, then a number, then enter, then ctrl-c. Thanks, Chris |
I have no idea how to help you. You'd best post this message to the Lift mailing list. |
| In CHAPTER 2, P.17, Note 3 reads: 3. Option[Int] is a “variant type” or “sum type” seems to be 3. Option[Int] is a “variant type” or “some type” |
it is correct as printed. See http://en.wikipedia.org/wiki/Tagged_union |
| Chapter 7, page 184 - Structural type Change Handler WORK case class ChangeEvent[OnType](on: OnType) trait Listener[T] { this: T with Listener[T] => type ChangeHandler = { //def changed(c: ChangeEvent[T with Listener[T]]): Unit def changed(c: ChangeEvent[T]): Unit } private var listeners: List[ChangeHandler] = Nil def addListener(c: ChangeHandler) = synchronized {listeners ::= c} def removeListener(c: ChangeHandler) = synchronized {listeners -= c} protected def updateListeners() = synchronized { //val ch = ChangeEvent(this) val ch = ChangeEvent[T](this) listeners.foreach(i => i.changed(ch)) } } class Foo extends Listener[Foo] { private var _count = 0 def count = synchronized{_count} def inc = synchronized{ _count += 1 updateListeners() } } scala> val f = new Foo f: Foo = Foo@1a15597 scala> object Bar { | def changed(c: ChangeEvent[Foo]) {println("changed: "+c.on.count)} | } defined module Bar scala> f.addListener(Bar) scala> f.inc changed: 1 scala> f.inc changed: 2 |
Thanks |
| Chapter 3, page 81. I get an IOException when loading xml from demo.liftweb.net from the console. I can see it using my browser. scala> val xml = XML.load("http://demo.liftweb.net/") java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1305) at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:677) at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.s... scala> val xml = XML.load("http://localhost:8080/") java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1305) at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:677) at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.s... |
The W3C changed their policy toward JVM-based access to the DTDs. |
| Chapter 3 page76. "XML in your Scala code" 8th line from the bottom, reads: and Node is a superclass of NodeSeq, which is a subclass of Seq[Node]. seems to be and Node is a subclass of NodeSeq, which is a subclass of Seq[Node]. |
Thanks |
| PAGE 28 CHAPTER 2 I SCALA SYNTAX, SCRIPTS, AND YOURFIRST SCALA PROGRAMS You declare the parameters inside the methoddeclaration’s parentheses THERE MUST BE A SPACE BETWEEN method AND declaration's |
I have no idea what this means. |
| Chapter 7, page 184 - Structural type Change Handler not working scala> val f = new Foo f: Foo = Foo@36c51c9c scala> object Bar { | def changed(c: ChangeEvent[Foo]) {println("changed: "+c.on.count)} | } defined module Bar scala> f.addListener(Bar) <console>:7: error: type mismatch; found : Bar.type (with underlying type object Bar) required: f.ChangeHandler f.addListener(Bar) |
Apparently Scala's treatment of structural types changed from 2.7.4 and 2.7.5 |
| Chapter 1, page 8 Mac OS X instructions do not seem to work |
How do they fail? |
| page 281 bottom half Q: Why not use Rails, which has great developer productivity? A: Rails is great from person-to-computer applications, should be Q: Why not use Rails, which has great developer productivity? A: Rails is great for person-to-computer applications, changing the "from" to "for" |
Thanks. |
| Chapter 3, page 67, Map section - Not an error, but p + 8 -> "Archer" gets a deprecation warning under 2.7.5.final. Use p + ((8, "Archer")) instead. |
And it will probably change for 2.8 :-) |
| Chapter 2, page 29 - The definition of sum() doesn't seem to work without casting. For example: scala> sum(5.0d) <console>:10: error: inferred type arguments [Double] do not conform to method sum's type parameter bounds [T <: java.la ng.Number] sum(5.0d) ^ I think the problem is that Double falls into the Scala type hierarchy, so isn't a subclass of java.lang.Number. Casting to Java classes is clumsy, but works: scala> sum(int2Integer(5), double2Double(6.0)) res41: Double = 11.0 |
You are correct, the type bounds are Number. Thus a java.lang.Number must be passed for each of the paramters. Where is the errata? |
| Chapter 2, page 25 - the twoMeows method won't compile. It uses "otherparam" in the arg list, but "param" in the method body. | Thanks |
| Chapter 2, page 47,8th line, reads: there’s no reason way to use mixins seems to need to be there’s no reasonable way to use mixins |
Thanks |
| Chapter 2. Executed the following in the WinXp DOS command window: scala Sum.scala Entered: 1 <Enter> 2 <Enter> 3 <Enter> Ctrl-C has no effect Ctrol-Z follwed by <Enter> does. Don't why :-). |
The code should read "ctrl-D (Windows)" |
| Chapter 3, p. 49: "In Java, String, int, long, double, and boolean are all immutable data types." This should read: "In Java, String, Integer, Long, Double, and Boolean are all immutable data types." |
It reads correctly. In Java, the primitive data types are immutable. |
| Ch. 4, page 110, the definition of bmap seems to be irrelevant, it is repeated on page 111. also, inside it "val ret" should probably be "var ret" | Please read the text surrounding the example. Just as with all non-trivial code in the book, we give a complete listing first for those that want to type it in. Next we go through the code concept-by-concept. So, yes, the code for the bmap method appears twice in the book. Once as part of the whole listing and then again as I explain how it works. And, no, it should not be a var, it should be a val. The reference of ret does not change during method execution. The reference points to a mutable ListBuffer and the += method on ListBuffer mutates the underlying ListBuffer, but does not change the reference that ret points to. |
