| | @@ -628,3 +628,47 @@ |
| 628 | 628 | thread, which can only set a flag that the turn reads after each read |
| 629 | 629 | of the reply; a server that says nothing for a minute, as a model does |
| 630 | 630 | while it thinks, keeps the turn going for that minute. |
| 631 | + |
| 632 | +## An empty array constant for a slice |
| 633 | + |
| 634 | +`const Runs: []Run = [];` is an error: "an array's length is from 1 |
| 635 | +to 2^40, found 0". A constant typed `[]T` is an array constant whose |
| 636 | +length is its literal's (4), and an array has at least one element |
| 637 | +(5.2), so the empty literal has no array to be. Yet `[]` is the empty |
| 638 | +slice everywhere else (6.5), and a slice of no elements is what such a |
| 639 | +table may well be. |
| 640 | + |
| 641 | +The proposal: a constant typed `[]T` whose literal is `[]` is the empty |
| 642 | +slice, as a slice variable starts, and no array at all; `LEN` of it is |
| 643 | +0. Arrays stay at least one long; only the slice constant changes. A |
| 644 | +program that compiles today means the same, so it breaks none. |
| 645 | + |
| 646 | +It costs a sentence of 4, and in the compiler, `literalArray` giving |
| 647 | +the slice type back for a length of 0 instead of the error. |
| 648 | + |
| 649 | +Met in rrem's `RremUcd`, whose tables `tools/Ucd.raz` writes: before |
| 650 | +the tool's first run, each table needs a placeholder of one element, |
| 651 | +which the code reading it must then not take for a real one. |
| 652 | + |
| 653 | +## `Vec.pop` |
| 654 | + |
| 655 | +`Vec` can push but not pop: taking the last element off is two calls |
| 656 | +and an index written out, |
| 657 | + |
| 658 | +``` |
| 659 | +b := Backs.all(ADR(re^.stack))[re^.stack.len - 1]; |
| 660 | +Backs.resize(ADR(re^.stack), re^.stack.len - 1); |
| 661 | +``` |
| 662 | + |
| 663 | +where a stack wants one. The proposal, in `Vec`, beside `push`: |
| 664 | + |
| 665 | +``` |
| 666 | +proc pop*(v: ^Vec): (T, BOOL); (* the last element, taken off; false if the array is empty *) |
| 667 | +``` |
| 668 | + |
| 669 | +as `List.pop` gives the front of a list. It keeps the memory, as |
| 670 | +`resize` does. It breaks no program, so it could come with any |
| 671 | +release, not only a thaw. |
| 672 | + |
| 673 | +Met in rrem's machine, whose backtracking stack is a `Vec` popped in |
| 674 | +`back` and `unwind`. |