Aladdin - Scala Bugtracking
[#906] project: documentation priority: low category: bug
submitter assigned to status date submitted
Nikolay Stephane fixed 2007-01-19 10:55:09.0
subject [contrib #280] Invalid code in An Introduction to Scala
code
Some code in "An Introduction to Scala" does not compile
with current Scala compilers (e.g. 2.3.1).


p7 (javac) illegal start of expression
public String mail() default = "";
should be
public String mail() default "";


p12 Automatic User-Defined Coercions

// error: method coerce is defined twice
def coerce: Float = numerator.asInstanceOf[Float] / denominator
def coerce: Double = numerator.asInstanceOf[Double] / denominator

// error: type mismatch;
//  found   : examples.Frac
//  required: scala.Double
Console.println(Math.sqrt(Frac(1,2)) + ", " +

This came up in the newsgroup:-
http://article.gmane.org/gmane.comp.lang.scala/3238
http://article.gmane.org/gmane.comp.lang.scala/3239
http://article.gmane.org/gmane.comp.lang.scala/3240

I suspect that views made coerce obsolete and that the example should use views and thus appear later in the document. Is this correct?


p35 Obsolete use of with without extends:
object GraphTest with Application {
should be
object GraphTest extends Application {


p37 private class LoopUnlessCond escapes its defining scope
private class LoopUnlessCond(body: => Unit) {
should be
class LoopUnlessCond(body: => Unit) {
(Alternately, the return type of loop should be a public class or trait that LoopUnlessCond extends.)


p41 prefix method name with `&'
set += main // add the main function
should be
set += &main // add the main function
what happened
Compiler errors
what expected Successful compiles. I suspect the examples were written for an older version of the language and haven't been updated.
[back to overview]
Changes of this bug report
Nikolay  edited on  2007-01-19 10:55:37.0
contribution #280
Stephane  edited on  2007-01-22 15:49:51.0
p07 added compilation of Java source code p12 removed obsolete page on coercions p35 not repro p37 not repro