import std::io; # A range of an enum's members gives each value once, in order, passing over # those no member has: in place, as a value, unrolled, and while checking. enum color: u8 { red, green = 4, blue } enum level { low = -2, mid, high = 3, top, zero = 0 } enum bits: u64 { one = 1, two = 2, four = 4, high = 0x8000000000000000 } def through(n: i64): i64 { var t := 0; for i in 0..=n { t += i; } return t; } def levels(): i64 { var t := 0; for l in level::low..=level::top { t = t * 10 + (l as i64 + 3); } return t; } const six := through(3); const counted := levels(); def walk(a: T, b: T): u64 where T: ordinal { var n: u64 = 0; for x in a..=b { n++; } val r := a..b; return n * 10 + r.remaining(); } def main(): void { print($"{six} {through(3)} {counted} {levels()} "); for c in color::red..=color::blue { print($"{c},"); } for c in color::red..color::blue { print($"{c};"); } println(""); for l in level::low..=level::top { print($"{l} "); } for x in bits::one..=bits::high { print($"{x} "); } println(""); var r := color::red..=color::blue; print($"{r.remaining()} {r.contains(color::green)} "); for c in r.rev() { print($"{c} "); } var w := level::low..=level::top; print($"{w.nth(2) else level::low} {w.remaining()} "); for l in (level::low..=level::top).step(2) { print($"{l} "); } println(""); for const c in color::red..=color::blue { print($"{c as u8} "); } var both := level::low..=level::top; while both.next() is some(front) { print($"{front} "); if both.next_back() is some(back) { print($"{back} "); } } println($"{walk(color::red, color::blue)} {walk(level::mid, level::high)} {walk(2, 5)}"); }