<commit_before>package examples.actors

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

object message {
  def main(args: Array[String]) = {
    val n = try { Integer.parseInt(args(0)) }
    catch {
      case _ =>
        scala.Console.println("Usage: examples.actors.Message <n>")
        Predef.exit
    }
    val nActors = 500
    val finalSum = n * nActors
    Scheduler.impl = new SingleThreadedScheduler

    def beh(next: Actor, sum: int): unit =
      react {
        case value: int =>
          val j = value + 1; val nsum = sum + j
          if (next == null && nsum >= finalSum)
            Console.println(nsum)
          else {
            if (next != null) next ! j
            beh(next, nsum)
          }
      }

    def actorChain(i: Int, a: Actor): Actor =
      if (i > 0) actorChain(i-1, actor(beh(a, 0))) else a

    val firstActor = actorChain(nActors, null)
    var i = n; while (i > 0) { firstActor ! 0; i = i-1 }
  }
}<commit_msg>Fixed termination bug in messages actors example.<commit_after>package examples.actors

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

object message {
  def main(args: Array[String]) = {
    val n = try { Integer.parseInt(args(0)) }
    catch {
      case _ =>
        println("Usage: examples.actors.message <n>")
        Predef.exit
    }
    val nActors = 500
    val finalSum = n * nActors
    Scheduler.impl = new SingleThreadedScheduler

    def beh(next: Actor, sum: int): unit =
      react {
        case value: int =>
          val j = value + 1; val nsum = sum + j
          if (next == null && nsum >= n * j)
            println(nsum)
          else {
            if (next != null) next ! j
            if (nsum < n * j) beh(next, nsum)
          }
      }

    def actorChain(i: Int, a: Actor): Actor =
      if (i > 0) actorChain(i-1, actor(beh(a, 0))) else a

    val firstActor = actorChain(nActors, null)
    var i = n; while (i > 0) { firstActor ! 0; i = i-1 }
  }
}
{'fraction_non_alphanumeric': 0.1255766273705792, 'fraction_numerical': 0.011276268580215274, 'mean_word_length': 1.998463901689708, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7130310', 'n_tokens_mistral': 677, 'n_tokens_neox': 637, 'n_words': 193}