53b43b0f79
Ship the QUALITY_PLAN stretch from ownership through ecosystem: C.1 lifetime elision (bootstrap + selfhost), bux fmt/test/doc CI hooks, stdlib goldens, package registry (bux search/add), and LSP 0.4 position-sensitive locals with inferred let types. Full-tree format pass plus Map/Set remove double-free fix.
39 lines
780 B
Plaintext
39 lines
780 B
Plaintext
// Methods - Struct with methods using extend
|
|
import Std::Io::{PrintLine, PrintInt};
|
|
|
|
|
|
struct Rectangle {
|
|
width: int;
|
|
height: int;
|
|
}
|
|
|
|
extend Rectangle {
|
|
func Area(self: Rectangle) -> int {
|
|
return self.width * self.height;
|
|
}
|
|
|
|
func Perimeter(self: Rectangle) -> int {
|
|
return 2 * (self.width + self.height);
|
|
}
|
|
}
|
|
|
|
func Main() -> int {
|
|
let rect: Rectangle = Rectangle { width: 10, height: 5 };
|
|
|
|
PrintLine("Rectangle:");
|
|
PrintLine("Width = ");
|
|
PrintInt(rect.width);
|
|
PrintLine("");
|
|
PrintLine("Height = ");
|
|
PrintInt(rect.height);
|
|
PrintLine("");
|
|
PrintLine("Area = ");
|
|
PrintInt(rect.Area());
|
|
PrintLine("");
|
|
PrintLine("Perimeter = ");
|
|
PrintInt(rect.Perimeter());
|
|
PrintLine("");
|
|
|
|
return 0;
|
|
}
|