Skip to content

Instantly share code, notes, and snippets.

View christineponyl's full-sized avatar

Adam Jallad christineponyl

View GitHub Profile
actor Main
new create(env: Env) =>
env.out.print(fib(5).string())
fun fib(n: U64): U64 =>
match n
| 0 => 0
| 1 => 1
else
// how to send snapshot of values from mutable container field to another actor
use "itertools"
use mut = "collections"
use "collections/persistent"
actor Receiver
let env: Env
new create(env': Env) =>
env = env'
// pass a copy of a (portion of) mutable array to another actor
// original array must be iso, trn or ref (#mutable)
// send as iso or val
// 1. iso copy-by-value to val
// 2. iso -> "make a copy" -> recover to val
// 3. ref -> clone -> recover to val
use "itertools"
use "collections"
actor Main
new create(env: Env) =>
try
let foo = Foo.create()?
something_else(foo)
else
env.err.print("Something went wrong!")
env.exitcode(1)
end
actor Main
let foo: (Foo|None)
new create(env: Env) =>
try
foo = Foo()?
else
env.err.print("Something went wrong!")
env.exitcode(1)
end
actor Main
let foo: Foo
new create(env: Env) =>
try
foo = Foo()?
else
env.err.print("Something went wrong!")
env.exitcode(1)
end
use "collections"
// the refcap of the Printer class constructor:
// if declared as iso, trn, or val, compiler demands sendable parameters
// if declared as ref or box, the compiler accepts the non-sendable parameter (box in this case)
class Printer
let env: Env
new val create(env':Env, arr:Array[USize] iso) =>
env = env'
use "collections"
// the refcap of the Printer class constructor:
// if declared as iso, trn, or val, compiler demands sendable parameters
// if declared as ref or box, the compiler accepts the non-sendable parameter (box in this case)
class Printer
let env: Env
new val create(env':Env, arr:Array[USize] box) =>
env = env'
use "collections"
class Printer
let env: Env
new val create(env':Env, arr:Array[USize] box) =>
env = env'
try
env.out.print(arr(4)?.string())
else
env.out.print("index out of range")
actor Main
new create(env: Env) =>
env.out.print("Hello, world!")