raz / commit b1a880ea

commit
b1a880ea02de9522be62076ef79f5f029d8775f9
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
4e7b5673
Report 2026-10.16: record constants, and Str.copy

An array or record constant holds records, strings as []U8, array
constants as slices, procedures, ERRORs and nil, as well as numbers:
a table of rules or key bindings is a constant in read-only data.
Str.copy copies a slice into memory from an allocator. By the
owner's word.

patch · log

1 file changed, +21 -11

doc/raz.md (history) modified +21 -11

@@ -9,7 +9,7 @@
99 This report defines the language. It is short on purpose. Whatever it
1010 doesn't allow, raz doesn't have.
1111
12-This is version 2026-10.15 of the report; section 12 says what each
12+This is version 2026-10.16 of the report; section 12 says what each
1313 version changed. 2026-10.11 and 2026-10.12 are a thaw the owner chose,
1414 for a language anyone can build again. They break programs written
1515 for 2026-10.10 and before: for 2026-10.9, say, the report of compiler
@@ -298,7 +298,8 @@
298298 **Constants** are evaluated by the compiler. Their expressions use only
299299 literals, other constants, operators, conversions, `SIZE` and the `LEN`
300300 of arrays and strings. A constant is an integer, a real, a `BOOL`, a
301-name of an enumeration, a set, a string, an array or an `ERROR`. A constant of an integer type wraps as the
301+name of an enumeration, a set, a string, an array, a record or an
302+`ERROR`. A constant of an integer type wraps as the
302303 program would: `U8(250) + 10` is 4. Dividing by zero in a constant is
303304 an error, and so is dividing the smallest value of a signed type by -1,
304305 with `div` or `mod`, which stops a program (section 6.1). A string constant can be indexed and sliced as an array of
@@ -312,22 +313,27 @@
312313 w := Text[4..7]; (* "cat" *)
313314 ```
314315
315-A constant with a type is an `ERROR` (section 5.8) or an array. An
316-array constant has a type `[n]T`, where `T` is an integer type, a
317-real, `BOOL`, an enumeration or a set, and its value is an array
318-literal (section 6.5) of constants:
316+A constant with a type is an `ERROR` (section 5.8), an array or a
317+record, and the value of an array or record constant is a literal
318+(section 6.5) of constants. Its elements and fields are integers,
319+reals, `BOOL`s, enumerations, sets, `ERROR`s, procedures, `nil`, a
320+string for a `[]U8`, an array constant for a slice of its element type,
321+and arrays and records of these; no variant and no other pointer:
319322
320323 ```
321324 const Primes: [5]I64 = [2, 3, 5, 7, 11];
325+type Rule = record class: []U8; tag: INT; float: BOOL; end;
326+const Rules: [2]Rule = [{class: "firefox", tag: 2}, {class: "mpv", float: true}];
322327 ...
323328 p := Primes[i];
324329 ```
325330
326-It is used as a variable of that type is, but can't be changed: it can
327-be indexed and sliced, its `LEN` is `n`, it can be assigned and
328-compared, and it can be passed as a `[n]T` or a `[]T`. Its elements
329-are constant as a string's bytes are (section 5.10). An element of it
330-isn't a constant, even at a constant index.
331+It is used as a variable of that type is, but can't be changed: an
332+array constant can be indexed and sliced and its `LEN` is `n`, a
333+record constant's fields can be read, and either can be assigned,
334+compared as its type allows, and passed. Its parts are constant as a
335+string's bytes are (section 5.10). A part of it isn't a constant, even
336+at a constant index.
331337
332338 **Variables** of a module live as long as the program; variables of a
333339 procedure live as long as its call. Both start at zero: every byte of
@@ -1562,6 +1568,7 @@
15621568 module Str;
15631569 proc cmp*(a, b: []U8): INT; (* -1, 0 or 1 as a sorts before, with or after b, byte by byte *)
15641570 proc eq*(a, b: []U8): BOOL;
1571+proc copy*(a: ^Mem.Allocator; s: []U8): ([]U8, BOOL); (* s's bytes in memory from a; false if a has none *)
15651572 proc hash*(s: []U8): U64; (* FNV-1a, 64 bits *)
15661573 proc find*(s, sub: []U8): INT; (* where sub first starts in s, or -1 *)
15671574 proc hasPrefix*(s, p: []U8): BOOL;
@@ -1906,6 +1913,9 @@
19061913 - **2026-10.15.** `Math` gains `pow`, `ceil`, `round`, `log2`,
19071914 `log10`, `tan`, `asin`, `acos` and `atan`; `Sys` gains `space`
19081915 (section 11).
1916+- **2026-10.16.** Record constants, and array and record constants of
1917+ records, strings, procedures and more (section 4); `Str` gains
1918+ `copy` (section 11).
19091919
19101920 ## Appendix A. What an implementation chooses
19111921