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

Scala example source code file (Ref.scala)

This example Scala source code file (Ref.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, array, reftest, reftest

The Scala Ref.scala source code

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

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

class Ref[a](init: a) extends Join {
  
  object get extends Synchr[a](this) { case class C() extends SyncVar[a]; }
  object set extends Synchr[unit](this) { case class C(x: a) extends SyncVar[unit]; }
  object state extends Asynchr(this) { case class C(x: a); }

  rules (
    Pair(List(get, state), { case List(g @ get.C(), state.C(x) ) =>
      { g.set(x); state(state.C(x)) } }),
    Pair(List(set, state), { case List(s @ set.C(x), state.C(y) ) =>
      { s.set(()); state(state.C(x)) } })
  );

  state(state.C(init));
  
  def Get: a = get(get.C());
  def Set(x: a): unit = set(set.C(x));
}
*/
object RefTest {

  def main(args: Array[String]) = {
    System.out.println("Started.");
/*
    concurrent.ops.spawn({
      val r1 = new Ref(0);
      System.out.println("Reference r1 created.");
      System.out.println("Value r1 (first time) = " + r1.Get);
      r1.Set(42);
      System.out.println("Value r1 (second time) = " + r1.Get);
    });
    concurrent.ops.spawn({
      val r2 = new Ref(100);
      System.out.println("Reference r2 created.");
      System.out.println("Value r2 (first time) = " + r2.Get);
      r2.Set(89);
      System.out.println("Value r2 (second time) = " + r2.Get);
    });
*/
  }

}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala Ref.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.