Aladdin - Scala Bugtracking
[#895] project: documentation priority: low category: bug
submitter assigned to status date submitted
Nikolay Burak open 2007-01-16 16:34:40.0
subject [contrib #283] Invalid code in ScalaOverview
code
A number of errors were encountered when I attempted to build the code fragments in "An Overview of the Scala Programming Language"


page 6: forall doesn't compile

error: ')' expected but identifier found.
!exists(xs, x: T => !p(x))
                     ^
one error found

Is this a compiler bug? The code compiles if we replace
!exists(xs, x: T => !p(x))
with
!exists(xs, { x: T => !p(x) } )



page 6: hasZeroRow doesn't compile

error: ')' expected but '(' found.
exists(matrix, row: Array[int] => forall(row, 0 ==))
                                        ^
one error found

hasZeroRow does compile if we replace
exists(matrix, row: Array[int] => forall(row, 0 ==))
with
exists(matrix, { row: Array[int] => forall[int](row, .==(0)) } )

There may be other concise alternatives, I don't know.



page 6: missing argument
for (val x <- xs; 0 <= x) yield Math.sqrt
should be
for (val x <- xs; 0 <= x) yield Math.sqrt(x)



(Optional) page 7: missing constructor argument
val x: GenCell[String] = new GenCell[String]
should be
val x: GenCell[String] = new GenCell[String]("abc")
(string arbitrary)



page 8: wrong return type
def tail: List[Nothing] = throw new Error("Empty.tail")
should be
def tail: GenList[Nothing] = throw new Error("Empty.tail")



(Difficult?) page 8: compile errors in GenList[+T].less

error: value < is not a member of T
this.head < that.head ||
          ^
error: lower bound T does not conform to upper bound Ordered[S]
def less[S >: T <: Ordered[S]](that: List[S]) =
           ^

I don't have a suggestion for this one.



page 10: Test.main instantiates abstract class

Either change SensorReader.Display to not be abstract,
or replace
val d1 = new Display; val d2 = new Display
with
val d1 = new Display {}; val d2 = new Display {}



page 11: missing [T]
with RichIterator
should be
with RichIterator[T]



page 12, 13: missing [T], trait not abstract class
abstract class SyncIterator extends AbsIterator {
should be
trait SyncIterator[T] extends AbsIterator[T] {

abstract class LoggedIterator extends AbsIterator {
should be
trait LoggedIterator[T] extends AbsIterator[T] {



(Optional) page 12: missing [char]

StringIterator(someString) with RichIterator
with SyncIterator
should be
StringIterator(someString) with RichIterator[char]
with SyncIterator[char]

StringIterator(someString) with SyncIterator
with RichIterator
should be
StringIterator(someString) with SyncIterator[char]
with RichIterator[char]



page 15: findRest doesn't compile

error: illegal start of simple pattern
rest@(_*)) => rest
        ^
error: ')' expected but '}' found.
rest@(_*)) => rest
                   ^
two errors found


I don't have a suggestion for this one.



page 16: Missing ")" and incorrect argument order

else m.add(xs.head, sum(m)(xs.tail)
should be
else m.add(xs.head, sum(xs.tail)(m))

Note: this is the same example and error as in a different document
http://scala-webapps.epfl.ch/bugtracking/contribs/display.do?id=281



(Optional) page 16: Missing def and [a]
sort(xs: List[a])
can instead be
def sort[a](xs: List[a])



page 16: compile errors in expanded form of sort(yss)

error: ')' expected but '(' found

Is this a compiler bug? The code compiles if we replace
sort(yss)(xs: List[int] => list2ordered[int](xs)(int2ordered))
with
sort(yss)( { xs: List[int] => list2ordered[int](xs)(int2ordered) } )



page 17: compile errors in listToSet

x prepend xs;
should be
xs prepend x;

!isEmpty && (xs.head == x || xs.tail contains x)
should be
!xs.isEmpty && (xs.head == x || (xs.tail contains x))



page 17: Incorrect type for xs
a value xs of type List[T]
should be
a value xs of type GenList[T]
what happened
Compiler errors
what expected Successful compiles
[back to overview]
Changes of this bug report
Nikolay  edited on  2007-01-16 16:35:12.0
contribution #283
Martin  edited on  2007-01-23 16:58:33.0
I fixed everything except: page 15: findRest doesn't compile error: illegal start of simple pattern rest@(_*)) => rest ^ error: ')' expected but '}' found. rest@(_*)) => rest ^ two errors found This one if for Burak.