Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7909659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:31:56+00:00 2026-06-03T12:31:56+00:00

I was experimenting with actors in Scala. But I’m very curious about two things.

  • 0

I was experimenting with actors in Scala. But I’m very curious about two things. (1) Is there a way to declare an actor as a parameter to itself (as in the following code) without the use of another actor? (I’ve seen the Producer/Consumer example and many others, that declare an actor of one kind and use that as a parameter to another.) Also, (2) the statement in the main method that declares a new actor, but uses “_ : Actor” … what does that mean? It compiles (which I didn’t expect) but doesn’t work as I intended (which I expected).

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

// Code for declaring methods that actors can send and receive

class Actor1(subact: Actor) extends Actor {
  def act: Unit = {
    println("doing stuff...")
    while (true) {
      // Code here for methods ...
    }
  }
  this.start()
}

object foo {
  def main(args: Array[String]) : Unit = {
    val i = new Actor1(_ : Actor)
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:32:01+00:00Added an answer on June 3, 2026 at 12:32 pm

    (1)

    Yes, that is possible:

    class Foo(actor: => Actor) extends Actor {
      def act {
        loop {
          react {
            case x: String => actor ! x
          }
        }
      }
    }
    
    lazy val foo = new Foo(foo)
    
    foo.start
    
    foo ! "bar"
    

    But it doesn’t make much sense, as you always have a reference to the actor inside of itself ;-). And in this case it would just be like an infinite loop.

    (2) is very simple, you create a partially applied function:

    scala> class Foo(actor: Actor) {
         | println(actor.toString)
         | }
    defined class Foo
    
    scala> new Foo(_: Actor)
    res0: (scala.actors.Actor) => Foo = <function1>
    

    If you would store it into a variable and later call it with an actual instance of an Actor you would get an instance of your Actor1 class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From experimenting with the r.js optimizer, it seems that there is no way for
Experimenting with Swing, I learnt that there are two ways of using JOptionPane and
Experimenting with Scala... I'm trying to define something analogous to the @ hack in
I'm experimenting with Spring Mobile but I can't seem to get the basic example
In experimenting with scriptblocks, I was attempting to use a scriptblock parameter with an
Experimenting with MongoID on a Rails server and confused about how/where to set the
In experimenting with pickle, I've put together some code for a (very) simple blog.
I am currently experimenting with Actor-concurreny (on Python), because I want to learn more
Experimenting with existential types. Seems to be a great way to get some type
I am working on a little hobby project and am experimenting with doing things

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.