| | @@ -9,7 +9,7 @@ |
| 9 | 9 | This report defines the language. It is short on purpose. Whatever it |
| 10 | 10 | doesn't allow, raz doesn't have. |
| 11 | 11 | |
| 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 |
| 13 | 13 | version changed. 2026-10.11 and 2026-10.12 are a thaw the owner chose, |
| 14 | 14 | for a language anyone can build again. They break programs written |
| 15 | 15 | for 2026-10.10 and before: for 2026-10.9, say, the report of compiler |
| | @@ -298,7 +298,8 @@ |
| 298 | 298 | **Constants** are evaluated by the compiler. Their expressions use only |
| 299 | 299 | literals, other constants, operators, conversions, `SIZE` and the `LEN` |
| 300 | 300 | 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 |
| 302 | 303 | program would: `U8(250) + 10` is 4. Dividing by zero in a constant is |
| 303 | 304 | an error, and so is dividing the smallest value of a signed type by -1, |
| 304 | 305 | 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 @@ |
| 312 | 313 | w := Text[4..7]; (* "cat" *) |
| 313 | 314 | ``` |
| 314 | 315 | |
| 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: |
| 319 | 322 | |
| 320 | 323 | ``` |
| 321 | 324 | 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}]; |
| 322 | 327 | ... |
| 323 | 328 | p := Primes[i]; |
| 324 | 329 | ``` |
| 325 | 330 | |
| 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. |
| 331 | 337 | |
| 332 | 338 | **Variables** of a module live as long as the program; variables of a |
| 333 | 339 | procedure live as long as its call. Both start at zero: every byte of |
| | @@ -1562,6 +1568,7 @@ |
| 1562 | 1568 | module Str; |
| 1563 | 1569 | proc cmp*(a, b: []U8): INT; (* -1, 0 or 1 as a sorts before, with or after b, byte by byte *) |
| 1564 | 1570 | 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 *) |
| 1565 | 1572 | proc hash*(s: []U8): U64; (* FNV-1a, 64 bits *) |
| 1566 | 1573 | proc find*(s, sub: []U8): INT; (* where sub first starts in s, or -1 *) |
| 1567 | 1574 | proc hasPrefix*(s, p: []U8): BOOL; |
| | @@ -1906,6 +1913,9 @@ |
| 1906 | 1913 | - **2026-10.15.** `Math` gains `pow`, `ceil`, `round`, `log2`, |
| 1907 | 1914 | `log10`, `tan`, `asin`, `acos` and `atan`; `Sys` gains `space` |
| 1908 | 1915 | (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). |
| 1909 | 1919 | |
| 1910 | 1920 | ## Appendix A. What an implementation chooses |
| 1911 | 1921 | |