The Artima Developer Community


Errata for Actors in Scala
Chapter: All
Return to errata index.

Page 39 (PDF page 39):
The currying example looks wrong.

It is
def curriedAdd(x: Int)(y: Int) = x + x
...
add(3)(5)

but should be
def curriedAdd(x: Int)(y: Int) = x + y
...
curriedAdd(3)(5)
Page 26 (PDF page 43):
Figure 2.11
Whether this is an error can be debated, but the sequence of the
graphical (5) and (6) is the "wrong" way around. The direction of the
accompanying arrow is right-to-left!

Kudos: I really like the "space capsule" illustrations! ;-)
Page 53 (PDF page 53):
Listing 4.8:
val sessionUser = actor {
  while (true) {
    self.receiveWithin (1800 * 1000) {
    ...
    }
  }
}

self.receiveWithin (1800 * 1000) should be self.receiveWithin (180 *
1000) for 3 minutes
Page 34 (PDF page 53):
In Listing 3.1 Extending HttpServlet from Scala there is an extra dot in
the line that is calling the superclass init() method.

The line super.init.() should be super.init()
Page 56 (PDF page 56):
"Listing 5.1 shows the definition of a method that recursively builds a
chain of actors and returns the first actor" explanation at page 56 may
be misleading with given implementation. 
Returned actor is the last actor created by the buildChain method not the
first
(if we start numbering actors in order they are being created)
Page 57 (PDF page 57):
buildChain function creates size+1 actors with existing implementation

def buildChain(size: Int, next: Actor): Actor = {
...
size > 0) buildChain(size - 1, a)
    else a
..

should be:

def buildChain(size: Int, next: Actor): Actor = {
...
size > 1) buildChain(size - 1, a)
    else a
..
Page 39 (PDF page 58):
The currying example looks wrong.

It is
def curriedAdd(x: Int)(y: Int) = x + x

but should be
def curriedAdd(x: Int)(y: Int) = x + y
Page 61 (PDF page 61):
"Listing 5.5 shows how to do this by replacing the body of the chain
actors wit a call to waitFor method" 
explanation is not sufficient for the proper usage of multiple message
awaits:

Missing issues:

* First actor should receive n 'Die messages. Sample initialisation for 2
messages

    val lastCreated: Actor = buildChainModified(numActors, null)
    lastCreated ! 'Die
    lastCreated ! 'Die

* Also main should await for n number of consecutive Ack messages, Sample
usage for 2 messages:
   
  receive {
      case 'Ack =>
        receive {
          case 'Ack =>
            val end = System.currentTimeMillis()
            println("MODIFIED VERSION: Took " + (end - start) + " ms for
the creation of " + numActors + " Actors")

        }
    }
Page 67 (PDF page 67):
Listing 5.10 deoes not work properly: 

when loop is constructed with while and receive is used, works as
expected 

however when updated to loopWhile and react, with the given
implementation, you may and most probably get
scala.actors.SuspendActorControl
Page 49 (PDF page 67):
"In using ! to denote message sending, Scala follows the tradition of
Erlang:"

The use of "!" for message sending in occam (1983) predates the usage in
Erlang (1986).
I am not 100% sure, but if I'm not mistaken some variants of CSP already
used the "!" earlier.
Page 68 (PDF page 68):
val it = iter.elements line in Listing 5.12 should be  val it =
iter.toIterator
Page 57 (PDF page 75):
Listing 5.1 uses symbols, but these are explained only on page 72 (in
footnote 1 - should be moved to page 57).
Page 76 (PDF page 76):
Listing 6.2 will give Wrong forward reference,
Can not be evaluated at Scala console either.
Slave can be defined as an inner object of Master as:

import scala.actors.Actor
import scala.actors.Actor._

object Master extends Actor {
  def act() {
    Slave ! 'doWork
    react {
      case 'done =>
        throw new Exception("Master crashed")
    }
  }

  object Slave extends Actor {
    def act() {
      link(Master)
      loop {
        react {
          case 'doWork =>
            println("Done")
            reply('done)
        }
      }
    }
  }
}


scala> Master.Slave.start()
res0: scala.actors.Actor = Master$Slave$@267fbe19

scala> Master.Slave.getState
res1: scala.actors.Actor.State.Value = Suspended

scala> Master.start()
res2: scala.actors.Actor = Master$@22006edb

scala> Done
Master.getState
res3: scala.actors.Actor.State.Value = Terminated

scala> Master.Slave.getState
res4: scala.actors.Actor.State.Value = Terminated
Page 65 (PDF page 83):
Listing 5.9 (and several later listings) use the @ syntax in pattern
matching without explaining it.
Page 88 (PDF page 88):
Listing 7.2:

joeActor should be started before sending a message to it

Ex:

ActorWithThreadLocalWrong.joeActor.start()
println("Your name: " + (ActorWithThreadLocalWrong.joeActor !?
'YourName))
println("Your name: " + (ActorWithThreadLocalWrong.joeActor !? 'YourName))
Page 72 (PDF page 89):
End of first paragraph says "After that, the actor terminates normally"
which is probalbly wrong, considering that page 148 (also end of first
paragraph there) says "execution continues with the current continuation
closure".
Page 97 (PDF page 97):
ManagedBlocker trait used in Listing 7.7 is deprecated and cannot be used
as declared with private in library

blocking can be used instead as suggested :

import scala.actors.Actor._
import scala.actors.Actor

import scala.concurrent._

import
Page 81 (PDF page 98):
Program output should not be colorized in eBook, e.g. output of listing
6.5, starting "I'm (re-)born".
Page 116 (PDF page 116):
Listing 9.4 would cause an error as:

..
  case Exit(from, reason) =>

          //Retrieve assigned work:
          //from: type mismatch, expected Actor, actual: AbstractActor
          val (key, value) = assignedMappers(from)
Page 122 (PDF page 122):
a1 ! Broadcast("Hello", Set(a1, a2, a3, a4)) lines at page 122 should be:

a1 ! BCast("Hello", Set(a1, a2, a3, a4)) 

(see BCast case class definition at page 120)
Page 124 (PDF page 124):
Please note that

akka.actors.Channel trait does not exist in current akka versions
(available only in 1.3)
Page 126 (PDF page 126):
For the akka.actor.Channel trait removal after akk averisons 1.3,

see:
http://doc.akka.io/docs/akka/2.0/project/migration-guide-1.3.x-2.0.x.html

v1.3:

self.channel ! result
self.channel tryTell result
self.reply(result)
self.tryReply(result)
v2.0:

sender ! result
Page 115 (PDF page 131):
In Fig 9.1, in the left table the heading should be V1=List[String], not
List[File].
Page 133 (PDF page 133):
- Listing 10.4 uses case object Start that is not defined at Listing 10.3
- to be able to send synchronous messages you need to import
akka.pattern.ask (se
http://doc.akka.io/docs/akka/2.0/project/migration-guide-1.3.x-2.0.x.html)
Page 121 (PDF page 137):
Listing 9.7 uses the orElse method which has not been explained yet.
Page 126 (PDF page 142):
Listing 10.1 uses _ to initialize a var, which has not been explained yet.

Copyright © 2024 Artima, Inc. All rights reserved.