Something went wrong. Try again.
Something went wrong. Try again.
470 B 23 lines
at runtime
123456789101112131415161718192021222324import std::iostruct Point { x: int, y: int,
fn translate(self: Self, dx: int, dy: int): int { let nx = self.x + dx; let ny = self.y + dy; return nx + ny; }
fn scale(self: Self, factor: int): int { return (self.x + self.y) * factor; }}
fn main(): int { let p = Point { x: 10, y: 20 }; let t = p.translate(5, 3); let s = p.scale(2); io::printf("translate=%d scale=%d\n", t, s); return 0;}