You can only modify vars at a class level. This is intentional because actors don't like in-place updates -- it really doesn't jive well with lock-free concurrency.
Functions, by default, have the box capability, which means that data manipulated by this function are read-only. To ensure that the function can mutate data, the method will need to be declared fun ref.
actor Main
var i: U32 = 0
fun ref foo() =>
i = i + 1
new create(env: Env) =>
env.out.print(i.string())
foo()
env.out.print(i.string())
You can only modify
var
s at a class level. This is intentional because actors don't like in-place updates -- it really doesn't jive well with lock-free concurrency.Functions, by default, have the
box
capability, which means that data manipulated by this function are read-only. To ensure that the function can mutate data, the method will need to be declaredfun ref
.Playground