[] as the empty slice, tested (report 2026-10.30); the compiler follows 2026-10.31 The compiler already made [] a nil pointer and a length of 0, and let it be returned: conform/run/EmptySlice pins it, through a view, which the seed doesn't know. raz --version says report 2026-10.31, whose thaw the next steps build.
| @@ -0,0 +1,4 @@ | ||
| 1 | +2 20 | |
| 2 | +not found, 0 | |
| 3 | +empty, as a variable starts | |
| 4 | +0 |
| @@ -0,0 +1,43 @@ | ||
| 1 | +(* [] used as a slice is the empty slice, as a slice variable starts, | |
| 2 | + and no variable of the procedure: it may be returned beside an error | |
| 3 | + (report 2026-10.30, sections 6.5 and 7.3). *) | |
| 4 | +module EmptySlice; | |
| 5 | +import Out; | |
| 6 | + | |
| 7 | +type Pair = record a, b: INT; end; | |
| 8 | + | |
| 9 | +const NotFound: ERROR = "not found"; | |
| 10 | + | |
| 11 | +var pairs: [3]Pair; | |
| 12 | + | |
| 13 | +(* The pairs from the first whose a is key on, or none and NotFound. *) | |
| 14 | +proc from(key: INT): ([]Pair, ERROR); | |
| 15 | +var i: INT; | |
| 16 | +begin | |
| 17 | + for i := 0 to LEN(pairs) - 1 do | |
| 18 | + if pairs[i].a = key then return pairs[i..LEN(pairs)], nil; end; | |
| 19 | + end; | |
| 20 | + return [], NotFound; | |
| 21 | +end; | |
| 22 | + | |
| 23 | +proc none: []INT; | |
| 24 | +begin | |
| 25 | + return []; | |
| 26 | +end; | |
| 27 | + | |
| 28 | +proc main*; | |
| 29 | +var s: []Pair; e: ERROR; t, u: []INT; w: [2]INT; | |
| 30 | +begin | |
| 31 | + pairs := [{a: 1, b: 10}, {a: 2, b: 20}, {a: 3, b: 30}]; | |
| 32 | + s, e := from(2); | |
| 33 | + Out.int(LEN(s)); Out.str(" "); Out.int(s[0].b); Out.ln; | |
| 34 | + s, e := from(9); | |
| 35 | + if e = NotFound then Out.str("not found, "); Out.int(LEN(s)); Out.ln; end; | |
| 36 | + t := none(); | |
| 37 | + w := t.([2]INT); (* ptr and len (5.3) *) | |
| 38 | + if (w[0] = 0) and (w[1] = 0) then Out.str("empty, as a variable starts\n"); end; | |
| 39 | + u := []; | |
| 40 | + Out.int(LEN(u)); Out.ln; | |
| 41 | +end; | |
| 42 | + | |
| 43 | +end EmptySlice. |
| @@ -29,7 +29,7 @@ | ||
| 29 | 29 | import Sys, Out, Version, Files, Fmt, Diag, Scan, Sym, Chunk, X64, Gen, Parse, Link, Elf; |
| 30 | 30 | |
| 31 | 31 | const |
| 32 | - Report = "2026-10.29"; (* the version of doc/raz.md it follows *) | |
| 32 | + Report = "2026-10.31"; (* the version of doc/raz.md it follows *) | |
| 33 | 33 | MemfdCreate = 319; (* the system call *) |
| 34 | 34 | MfdCloexec = 1; (* an ELF still executes: the kernel opens it first *) |
| 35 | 35 | Execve = 59; |
| @@ -13,8 +13,9 @@ | ||
| 13 | 13 | # converts the narrower of two integers; and views, v.(T), |
| 14 | 14 | # whose tests are conform/*/View*.raz, and which Math, examples/Elf.raz |
| 15 | 15 | # and, through Math, test/bench/NBody.raz use; and returning a slice of |
| 16 | -# the frame as an error (report 2026-10.27); and an array constant | |
| 17 | -# typed []T (report 2026-10.29). | |
| 16 | +# the frame as an error (report 2026-10.27); an array constant typed | |
| 17 | +# []T (report 2026-10.29); and [] as the empty slice, seen through a | |
| 18 | +# view (report 2026-10.30). | |
| 18 | 19 | newer="conform/run/RawStrings.raz conform/err/ScanRawOpen.raz conform/err/ScanRawIndent.raz |
| 19 | 20 | conform/run/MatchStr.raz conform/err/MatchStrTwice.raz conform/err/MatchStrNoElse.raz |
| 20 | 21 | conform/err/MatchStrVar.raz conform/err/MatchReal.raz conform/err/AtMatch.raz |
| @@ -23,7 +24,8 @@ | ||
| 23 | 24 | conform/err/IntResultsNarrow.raz conform/err/GenIntTypes.raz |
| 24 | 25 | lib/Math.raz examples/Elf.raz test/bench/NBody.raz |
| 25 | 26 | conform/err/FrameSlice.raz |
| 26 | - conform/run/ArrayConstLen.raz conform/err/ArrayConstLenEmpty.raz conform/err/ArrayConstLenLiteral.raz" | |
| 27 | + conform/run/ArrayConstLen.raz conform/err/ArrayConstLenEmpty.raz conform/err/ArrayConstLenLiteral.raz | |
| 28 | + conform/run/EmptySlice.raz" | |
| 27 | 29 | newer() { |
| 28 | 30 | case $1 in conform/*/View*.raz) return 0 ;; esac |
| 29 | 31 | for g in $newer; do [ $g = $1 ] && return 0; done |