- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Re: Actor: super.receive(f) works, super.receive(idFun andThen f) causes scala.MatchError
Mon, 2010-06-14, 16:56
On Mon, Jun 14, 2010 at 5:53 PM, Josh Suereth <joshua.suereth@gmail.com> wrote:
My bad! no harm meant.
Apology accepted. ;)
On Mon, Jun 14, 2010 at 11:51 AM, Viktor Klang <viktor.klang@gmail.com> wrote:
On Mon, Jun 14, 2010 at 5:43 PM, Josh Suereth <joshua.suereth@gmail.com> wrote:
Since no one else tackled this:
Erm, I sent a link to an implementation of a logging actor :p
Also, in the link was sample code to do PartialFunction filter and intercept
You're using Partial Functions improperly. That being, if you want to combine PartialFunctions, andThen will compose them. However, it assumes that each one *completely* matches the space, or throws an error.
If you want to join them "case-wise" so-to-speak you want to use the orElse function. When combining receive methods from an actor hierarchy, orElse is how you need to do it, unless you want the first function to be the only thing that has a chance to match against the input.
- Josh
P.S. - Not sure what variant of Scala you're using, but the code you posted is quite... uncompilable for me.
On Wed, Jun 9, 2010 at 5:35 PM, Stefan Kuhn <qn.666@gmx.net> wrote:
trait Logtor extends Actor ... {
val idFun : PartialFunction[Any, Any]= { case x => x}
abstract override def receive[R](f: PartialFunction[Any, R]): R = {
// super.receive(f) // <<< no error
super.receive(idFun andThen f) // <<< error!!!
//thesis.bsps.sort.WorkerNode@X: caught scala.MatchError: //PivotedSlice(2,X)
}
The error is non-deterministic but reproducible.
Tests exist which always produced the error.
Switch Line 16 vs 17 to see.
http://github.com/Stefanqn/Sbt_2.8/blob/master/src/main/scala/thesis/experimental/Logtor.scala
Testsuite is at:
Sbt_2.8/ src/test/scala/thesis/bsps/sort/RegularSamplingScalaActorsTest.scala
It's Scala RC3. The project is build with SBT with managed libs only.
Any ideas what's wrong?
By the way, the app sorts distributed, with RegularSampling / PSRS.
Thanks in advance
stefan