3b03d43dd1
- hello.bux: Hello World with PrintLine - fibonacci.bux: Recursive Fibonacci with while loop - factorial.bux: Recursive Factorial computation - structs.bux: Struct creation and field access All examples compile and run successfully via 'bux run'
30 lines
661 B
Plaintext
30 lines
661 B
Plaintext
// Structs - Basic struct usage
|
|
extern func Std_Io_PrintLine(s: String);
|
|
extern func Std_Io_PrintInt(n: int);
|
|
|
|
struct Point {
|
|
x: int;
|
|
y: int;
|
|
}
|
|
|
|
func AddPoints(a: Point, b: Point) -> Point {
|
|
let result: Point = Point { x: a.x + b.x, y: a.y + b.y };
|
|
return result;
|
|
}
|
|
|
|
func Main() -> int {
|
|
let p1: Point = Point { x: 10, y: 20 };
|
|
let p2: Point = Point { x: 5, y: 15 };
|
|
let sum: Point = AddPoints(p1, p2);
|
|
|
|
Std_Io_PrintLine("Point sum:");
|
|
Std_Io_PrintLine("x = ");
|
|
Std_Io_PrintInt(sum.x);
|
|
Std_Io_PrintLine("");
|
|
Std_Io_PrintLine("y = ");
|
|
Std_Io_PrintInt(sum.y);
|
|
Std_Io_PrintLine("");
|
|
|
|
return 0;
|
|
}
|