(* A constant's slice part written as an array literal (report section 4): each literal an array constant of its own, nested to any depth, inside records and variants too. *) module SliceLiteralConst; import Out; type Rule = record name: []const U8; keys: []const INT; end; Shape = variant dot; poly(xs: []const INT); end; const Rows: []const []const INT = [[1, 2], [3], []]; Deep: []const []const []const U8 = [[['a', 'b'], "cd"], [], [['e']]]; Rules: []const Rule = [{name: "up", keys: [107, 65]}, {name: "none", keys: []}]; Shapes: [2]Shape = [poly([1, 2, 3]), dot]; Words: []const []const U8 = [['h', 'i'], "there"]; proc sum(xs: []const INT): INT; var i, s: INT; begin s := 0; for i := 0 to LEN(xs) - 1 do s := s + xs[i]; end; return s; end; proc main*; var i, j: INT; begin for i := 0 to LEN(Rows) - 1 do Out.int(LEN(Rows[i])); Out.str(":"); Out.int(sum(Rows[i])); Out.str(" "); end; Out.ln; for i := 0 to LEN(Deep) - 1 do Out.str("["); for j := 0 to LEN(Deep[i]) - 1 do Out.str(Deep[i][j]); Out.str(" "); end; Out.str("]"); end; Out.ln; for i := 0 to LEN(Rules) - 1 do Out.str(Rules[i].name); Out.str(" "); Out.int(LEN(Rules[i].keys)); Out.str(" "); Out.int(sum(Rules[i].keys)); Out.ln; end; match Shapes[0] of | poly(xs): Out.int(sum(xs)); Out.ln; | dot: end; Out.str(Words[0]); Out.str(" "); Out.str(Words[1]); Out.ln; end; end SliceLiteralConst.