Initial Commit

This commit is contained in:
SoraKatadzuma committed 2026-12-06 13:52:57 -06:00
commit 528ccf1523
782 files changed
+145156

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
import std::io;
trait shape {
def area(this: &shape): f64;
def grow(this: &mut shape, by: f64): void;
}
struct square: shape { var side: f64; }
struct circle { var radius: f64; }
def square::area(this: &square): f64 { return this.side * this.side; }
def square::grow(this: &mut square, by: f64): void { this.side += by; }
def circle::area(this: &circle): f64 { return 3 * this.radius * this.radius; }
def circle::grow(this: &mut circle, by: f64): void { this.radius *= by; }
def report(s: &shape): string { return $"{s.area()} {s}"; }
def enlarge(s: &mut shape): void { s.grow(2); }
def main(): void {
var sq := square{3};
var ci := circle{1};
enlarge(&mut sq);
enlarge(&mut ci);
val shape_ref: &shape = &sq;
println($"{report(&sq)} {report(&ci)} {shape_ref.area()}");
}