Files

22 lines
699 B
Plaintext
Raw Permalink Normal View History

2026-10-26 10:14:11 -05:00
import std::io;
var total: i64 = 0;
struct counter { var n: i64; }
var counter::value: i64 {
get => this.n;
set => this.n = value;
}
val counter::doubled: i64 { get => this.value * 2; }
val counter::sign: i64 { get => this.n < 0 ? -1 : 1; }
val counter::seen: i64 { get => total + this.n; }
def bump(c: &mut counter): i64 { c.n = c.n + 1; return c.n; }
def add(a: i64, b: i64): i64 { return a + b; }
def tenfold(c: &mut counter): void { c.n = c.n * 10; }
def main(): void {
var c := counter{ n = 1 };
println($"{add(bump(&mut c), bump(&mut c))}");
c.value = 7;
total = 100;
println($"{c.value} {c.doubled} {c.sign} {c.seen}");
tenfold(&mut c);
println($"{c.value} {add(1, 2)}");
}