#1334 Actors

helium Sun 28 Nov 2010

I just found a blog post on Fantom actors. Maybe an interesting idea?

vkuzkokov Sun 28 Nov 2010

Cool method dispatching can be achieved through cool trap method. Actorlocals can be done with ivan's DSLs.

I believe the point of DSL was to create language extensions so that they will prove themeselves useful before being incorporated to the core language. actorlocal is one of those extensions.

brian Sun 28 Nov 2010

Interesting post.

If we did implement actor locals it would look something like this:

const class CounterActor 
{
  new make(ActorPool p)
  {
    actor := Actor(pool) |msg| { receive(msg) }
  }

  Int cur() { send(["cur"]).get }
  Void reset() { send(["reset"]) }
  Void increment(Int by := 1) { send(["increment", by]) } 

  private Obj? receive(Obj?[] msg) 
  {
    switch (msg.first)
    {
      case "cur": return value
      case "reset": value = 0; return null
      case "increment": value += msg[1]; return null
      default: throw Err("Invalid msg: $msg.first")
    }
  }

  private const Actor actor  
  private actorlocal Int value := 0
}

Login or Signup to reply.