# A program with no imports, which reads `core` alone, and names its types and # functions with nothing before them: `vector`, `box`, and `function`, the types # the syntax makes, traits, lanes, and atomics. It writes through `system`, by its # path, which reads that too. struct tally : equatable { var count: i64; } def tally::equals(&this, other: &tally): bool { return this.count == other.count; } def say(text: strview): void { system::fd::stdout.put(text); system::fd::stdout.put("\n"); } def total(values: span): T where T: integer { var sum: T = 0; for &each in values { sum = sum + each; } return sum; } def main(): void { var numbers := vector::::new(); for i in 0..5 { numbers.append(i * i); } val view: span = numbers.view(); say($"vector {numbers.length} total {total(view)} first {view[0]} last {view[4]}"); val boxed := box::::new(7); say($"owner {boxed.get()}"); val doubled := function::::new(def(x: i64): i64 { return x * 2; }); val both := pair:: { first = doubled(21), second = "pair" }; say($"function {both.first} {both.second}"); var found: maybe = nothing {}; if view.last() is some(&at) { found = at; } val parsed: result = 12; if found is some(value) && parsed is value(twelve) { say($"maybe {value} result {twelve}"); } var text := string::from("core", nothing {}); text.append(" alone"); val words: strview = text.view(); say($"string {text} {words.length} {words.upper()} {text.view() == words}"); var lanes := u32x4::splat(3) + u32x4::of([1, 2, 3, 4]); say($"lanes {lanes.sum()} {lanes.smallest()} {lanes.largest()} {count_ones(255u)}"); var counter := atomic::::new(1); _ = counter.fetch_add(4); say($"atomic {counter.load()} equal {tally { count = 1 } == tally { count = 1 }}"); }