1. Function parameters: sum :: func(a: int, b: int) int { return a + b; } foo :: func() { x := sum(1, 2); } 2. Multideclarations: a, b := 1, 2; /* Multiple assignment */ r, g, b, a: u8; /* Type cascading */ x, y, z: i8 = …; /* Multiple undefined assignment */ 3. Strings and arrays: hello_utf8 := "Hello, World"; hello_utf8: []u8 = "Hello, World"; hello_utf16: []u16 = "Hello, World"; hello_utf32: []u32 = "Hello, World"; X :: 3; xs := […]int{1, 2, 3}; /* Implicit length */ ys := [X]int{1, 2, 3}; /* Explicit length */ /* Assign specific indicies */ zs := […]int{ [2] = 123, [4] = 321, }; 4. Conditionals: if x > y { … } else if y < x { … } else { … } 5. Switch statements if x == { case 0; … case 1; … fallthrough; /* Explicit fallthrough; implicit break */ case 2; … default; … } 6. Loops loop { … } /* Infinite loop */ loop x > y { … } /* While loop */ loop x: xs { … } /* Range/for loop */ loop i: N…M { … } /* Loop i from N to M (integers) */ /* Break- and continue a loop iteration */ loop x > y { if x == 42 { break; } if x & 1 == 1 { continue; } … } /* Labeled break/continue */ outer :: loop { loop x > y { if x == 42 { break outer; } } } 7. Multiple return values from functions swap :: func(x, y: int) int, int { return y, x; } x, y := 1, 2; x, y = swap(x, y); /* Note that this is a function that returns a function! The returned function is one that takes an int and returns nothing */ foo :: func() (int) { … } 8. Default parameters foo :: func(x, y: int, flags: Flags = 0) { … } 9. Variadic parameters foo :: func(xs: …int) { for x: xs { … } foo(xs…); } 10. Structure types City :: struct { name, country: []u8; population: int; european := false; } växjö := City{"Växjö", "Sweden", 40'000, true}; são_paulo := City{ name = "São Paulo", country = "Brazil", population = 12.33e6, }; 11. Enumerations /* enum T ≣ enum(0, x + 1) T*/ Animal :: enum u8 { BEAR; /* 0 */ CAT; /* 1 */ DOG = 42; SNAKE; /* 43 */ } FileFlag :: enum(0, 1 << x) u8 { READ; /* 0x01 */ WRITE; /* 0x02 */ TRUNC; /* 0x04 */ EXEC = 0b0100'0000; /* 0x40 */ CLOEXEC; /* 0x80 */ RDWR = .READ | .WRITE; /* 0x3 */ } ByteSize :: enum(1, x * 1000) int { B; /* 1 */ KB; /* 1'000 */ MB; /* 1'000'000 */ GB; /* 1'000'000'000 */ TB; /* 1'000'000'000'000 */ } 12. Enum-indexed arrays Direction :: enum int { L; R; U; D; } Vector2 :: struct { x, y: int; } OFFSETS :: [Direction]Vector2{ .L = {-1, 0}, .R = {+1, 0}, .U = {0, +1}, .D = {0, -1}, } $add :: func (x, y: Vector2) Vector2 { return {x.x + y.x, x.y + y.y}; } x := Vector2{2, 4}; x += OFFSETS[.U]; /* x == Vector2{2, 5} */ x += OFFSETS[3]; /* Illegal */ x += OFFSETS[Direction{3}]; /* Legal */ 13. Operator overloading $add :: func(x, y: T1) T2 { … } $add, $sub, $mul, $div, etc. $dot, $cross, $star, etc. for Unicode operators (⋅, ×, ⋆, etc.)