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

  • Home
  • SEARCH
  • 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 6885627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:39:30+00:00 2026-05-27T05:39:30+00:00

How to solve this using scala Actors: I have a program that finds out

  • 0

How to solve this using scala Actors:
I have a program that finds out the frequencies of identifiers in files under a given path. The encoding assumed is UTF-8. I want to solve the same problem with scala actors.

//program to find frequencies of identifiers
import java.io._
import java.util.concurrent._
import java.util.concurrent.atomic._

object Main {
  // visit all files in dir
  def processDirectory(dir: File, visit: (File) => Unit) {
    for (f <- dir.listFiles) 
      if (f.isDirectory) processDirectory(f, visit)
      else visit(f)
  }

  //counters for all identifiers
  val frequencies = new scala.collection.mutable.HashMap[String, Int]

  // Finds all identifiers in a file and increments their counters
  def process(f: File) {
    val contents = scala.io.Source.fromFile(f, "UTF-8").mkString
    val pattern = "[a-zA-Z_][0-9a-zA-Z_]*".r
    for (m <- pattern.findAllIn(contents))
      frequencies(m) = frequencies.getOrElse(m, 0) + 1
  }

  def main(args: Array[String]) {   //Give path of a directory here
    processDirectory(new File(args(0)), process _)

    println("Ten most common identifiers:")
    val sorted = frequencies.values.toBuffer.sortWith(_ > _)
    for (i <- 0 until 10)      
      for ((k, v) <- frequencies) 
        if (v == sorted(i)) println(k + " " + v)
  }
}

Also please explain the concept of scala actors. I am confused about scala actors.

  • 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-05-27T05:39:30+00:00Added an answer on May 27, 2026 at 5:39 am

    Actors help with concurrent design. There’s nothing concurrent about this. People who want parallelism, for performance, sometimes want to do exactly what you’re doing: take some simple filesystem-munging thing, throw extra threads at it, and see if it’s faster. However, this is a disk, and random access is extremely expensive, so you’ve nothing to gain from parallel processing, Actor-abusing or otherwise.

    Scala’s Actors come from Erlang. So please see if Concurrency Oriented Programming in Erlang (pdf), by one of Erlang’s designers, helps you get an idea of what they’re about. They’re not really about throwing threads at tasks to make those tasks go faster.

    Some resources to help with Scala’s Actors:

    • Actors in Scala — it’s published at the end of the month, but PrePrint PDFs are available now.

    • Scala Actors: A Short Tutorial

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

Sidebar

Related Questions

I have been toying with some codes to solve this using a Levenberg-Marquardt solver
I could solve this using loops, but I am trying think in vectors so
Can anyone give me tips how to solve this using Graphs in C or
In my WPF application I have some drawing functionality. I have solved this using
I'm betting that someone has already solved this and maybe I'm using the wrong
This is something that I solved using reflection, but would like to see how
I am testing a parser I have written in Scala using ScalaTest. The parser
I am using ZedGraph's master pane to display two graphs that have synchronized X
I'm using Eclipse Scala plugin. I created a simple program: object HelloWorld { override
I am parsing XML file in scala using val data = XML.loadFile(changes.xml) I have

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.