This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actor Main | |
new create(env: Env) => | |
env.out.print(fib(5).string()) | |
fun fib(n: U64): U64 => | |
match n | |
| 0 => 0 | |
| 1 => 1 | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actor Main | |
let foo: (Foo|None) | |
new create(env: Env) => | |
try | |
foo = Foo()? | |
else | |
env.err.print("Something went wrong!") | |
env.exitcode(1) | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actor Main | |
let foo: Foo | |
new create(env: Env) => | |
try | |
foo = Foo()? | |
else | |
env.err.print("Something went wrong!") | |
env.exitcode(1) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actor Main | |
new create(env: Env) => | |
env.out.print("Hello, world!") |