// Feature 1 — heterogeneous protocol-constrained variadic pack. // // `..xs: Show` (no `[]`, no `$`) is a pack, not a slice: each call site // monomorphizes with the concrete per-position arg types, and `xs[i]` IS the // concrete element (comptime substitution, Decision 1) — so its own fields / // methods dispatch statically. `xs.len` is a comptime constant. Elements may // be DIFFERENT concrete types as long as each conforms to the protocol. // // (Conformance checking and projection `xs.T` / `xs.value` are still to come; // this locks in the per-shape binding + concrete-element access.) #import "modules/std.sx"; Show :: protocol(T: Type) { get :: (self: *Self) -> T; } IntBox :: struct { v: s64; } StrBox :: struct { s: string; } impl Show(s64) for IntBox { get :: (self: *IntBox) -> s64 => self.v; } impl Show(string) for StrBox { get :: (self: *StrBox) -> string => self.s; } howmany :: (..xs: Show) -> s64 { return xs.len; } sum2 :: (..xs: Show) -> s64 { return xs[0].v + xs[1].v; } describe :: (..xs: Show) -> void { // Heterogeneous: xs[0] is an IntBox, xs[1] a StrBox. print("describe len={} first={} second={}\n", xs.len, xs[0].v, xs[1].s); } main :: () -> s32 { a := IntBox.{ v = 42 }; b := IntBox.{ v = 7 }; print("count0={}\n", howmany()); // N=0 pack print("count2={}\n", howmany(a, b)); // N=2 print("sum={}\n", sum2(a, b)); // concrete field access via pack c := StrBox.{ s = "cool" }; describe(a, c); // heterogeneous IntBox + StrBox 0; }