Note that there are some explanatory texts on larger screens.

plurals
  1. POExtending Scala Actor
    primarykey
    data
    text
    <p>I'm new to scala. When learning Actor, I tried to extend it to save one line of def:</p> <pre><code>import scala.actors.Actor import Actor._ class Actoo(actoo: =&gt;Unit) extends Actor { def act() {actoo} } object run extends Application { /* // this one runs well val a = new Actor { def act() { receive { case 1 =&gt; println("1") } } } */ val a = new Actoo { receive { case 1 =&gt; println("1") } } a.start a ! 1 } </code></pre> <p>Then the exception trace looks like this:</p> <pre><code>java.lang.AssertionError: assertion failed: receive from channel belonging to other actor at scala.Predef$.assert(Predef.scala:92) at scala.actors.Actor$class.receive(Actor.scala:424) at Actoo.receive(actoo.scala:3) at run$$anon$1.&lt;init&gt;(actoo.scala:16) at run$.&lt;init&gt;(actoo.scala:15) at run$.&lt;clinit&gt;(actoo.scala) at run.main(actoo.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.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.scala:49) at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:74) at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:154) at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) </code></pre> <p>There may be many alternatives which can do the same thing, but it's better for me to know the reason why the code above doesn't work.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload