alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (parallelOr.scala)

This example Scala source code file (parallelOr.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

array, asynchr, c, c, join, list, list, pair, pair, synchr, synchr, syncvar

The Scala parallelOr.scala source code

/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003, LAMP/EPFL                  **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                  */

package examples.jolib;
/*
import concurrent.jolib._;
import concurrent.SyncVar;

/** Implementation in the join-calculus of a parallel OR. */
object or extends Join {
  
  object res extends Synchr[boolean](this) { case class C() extends SyncVar[boolean] };
  object res1 extends Asynchr(this) { case class C(b: boolean); }
  object res2 extends Asynchr(this) { case class C(b: boolean); }
  object res1False extends Synchr[boolean](this) { case class C() extends SyncVar[boolean] };
  object res2False extends Synchr[boolean](this) { case class C() extends SyncVar[boolean] };
  
  rules(
    Pair(List(res, res1), { case List(r @ res.C(), res1.C(b)) =>
      if (b) r.set(b) else r.set(res1False(res1False.C())) }),
    
    Pair(List(res, res2), { case List(r @ res.C(), res2.C(b)) =>
      if (b) r.set(b) else r.set(res2False(res2False.C())) }),
    
    Pair(List(res1False, res2),  { case List(r @ res1False.C(), res2.C(b)) =>
      r.set(b) }),
    
    Pair(List(res2False, res1),  { case List(r @ res2False.C(), res1.C(b)) =>
      r.set(b) })
  );
  
  def apply(b1: => boolean, b2: => boolean): boolean = {
    concurrent.ops.spawn(res1(res1.C(b1)));
    concurrent.ops.spawn(res2(res2.C(b2)));
    res(res.C())
  }
}
*/
object parallelOr {
  
  def main(args: Array[String]): unit = {
    def loop: boolean = { while (true) {}; true };
/*
    System.out.println("true || true = " + or(true, true));
    System.out.println("false || false = " + or(false, false));
    System.out.println("false || true = " + or(false, true));
    System.out.println("true || false = " + or(true, false));
    System.out.println("true || loop = " + or(true, loop));
    System.out.println("loop || true = " + or(loop, true));
*/
  }

}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala parallelOr.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.