Files
bux-lang/examples/pattern_matching.bux
T
dimgigov 92c5cd59f5 refactor: migrate examples to import Std::Io instead of raw extern func
- Create stdlib/Std/Io.bux with extern func declarations
- Rename C shim functions to short names (PrintLine, PrintInt, etc.)
- Update all 9 examples to use import Std::Io::{PrintLine, PrintInt};
- Remove manual extern func Std_Io_* declarations from examples
2026-05-31 02:01:28 +03:00

33 lines
626 B
Plaintext

// Pattern Matching - Match expressions with algebraic enums
import Std::Io::{PrintLine, PrintInt};
enum Option {
Some(int),
None
}
func GetValue(opt: Option) -> int {
match opt {
Option::Some(value) => opt.data.Some_0,
Option::None => 0
}
}
func Main() -> int {
let opt1: Option = Option { tag: Option_Some };
opt1.data.Some_0 = 42;
let opt2: Option = Option { tag: Option_None };
PrintLine("opt1 value: ");
PrintInt(GetValue(opt1));
PrintLine("");
PrintLine("opt2 value: ");
PrintInt(GetValue(opt2));
PrintLine("");
return 0;
}