package main import "moxie" // Example Moxie file exercising syntax highlighting. // // Moxie is a systems language for domain-isolated programs. Key differences from Go: // - string and []byte are the same type // - int32 and uint32 are always 32-bit (int/uint are illegal) // - no goroutines; spawn() creates isolated domains over IPC // - no new(), complex, uintptr; use &T{}, literal syntax, explicit pointers // - text concat uses |, not + // - push/pop/resize replace append // - fallthrough and go are compile errors const MaxWorkers = int32(4) type Job struct { id int32 name string } func worker(j moxie.Int32, out chan moxie.Int32) { out <- moxie.Int32(int32(j) * int32(j)) } func main() { // Slice size literals: []T{:len} and []T{:len:cap}. buf := []byte{:1024} queue := []int32{:0:100} // Channel and map literals (no make). results := chan moxie.Int32{} config := map[string]int32{ "timeout": 30, "maxRetries": 3, } // Text concatenation with |, not +. greeting := "hello " | "moxie" | "!" // Fan out: each spawn creates an isolated domain. for i := int32(0); i < MaxWorkers; i++ { spawn(worker, moxie.Int32(i), results) } // Event loop. for n := int32(0); n < MaxWorkers; n++ { select { case r := <-results: println(int32(r)) } } /* Range over text yields bytes, not runes. Use an encoding library for rune-level iteration. */ for i, b := range greeting { if b == ' ' { clear(buf[i:]) break } } // push replaces append: explicit growth, store-back implicit. push(queue, 1, 2, 3) last := pop(queue) resize(queue, 0) _ = config _ = last } // Multiple return values must be named. func divide(a, b float64) (result float64, err error) { if b == 0 { return 0, nil } return a / b, nil } // Generics with comparable constraint (no any/interface{}). func filter[T comparable](items []T, pred func(T) bool) (result []T) { result = []T{:0:len(items)} for _, item := range items { if pred(item) { push(result, item) } } return }