Sujet : Re: value-flavoured structures
De : ruvim.pinka (at) *nospam* gmail.com (Ruvim)
Groupes : comp.lang.forthDate : 04. Oct 2024, 08:17:28
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vdo4q8$4h5p$1@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Mozilla Thunderbird
On 2024-10-03 19:58, Anton Ertl wrote:
Ruvim <ruvim.pinka@gmail.com> writes:
On 2024-09-15 20:16, Anton Ertl wrote:
A major merit for value-flavoured structures is that you can change
the field size (e.g, from 1 byte to 2 bytes or vice versa) without
changing all the code accessing those fields. That's independent of
cell size.
>
Yes, you can change the field size, but only as far as its value
occupies the same number of a stack items and the stack is the same.
Yes. But you can switch between different sizes that all fit into a
cell, or between different memory sizes of floats without changing the
rest of the code.
Similar for the word `to` - `to` applies to the words created with
`value`, `fvalue`, `2value`. But the source code around `to foo` (and
`foo`) depends on the kind of `foo`, so the kind of `foo` cannot be
changed without changing the source code around where it is used.
That's just as for reading the value-flavoured field; if a field
pushes one cell, TO to the field also consumes one cell; likewise for
float fields.
BTW, this is the same when the separate getter and setter (as ordinary words) are used. Both for value-flavoured variables and value-flavoured structures.
### Comparison of using a to-based setter ("to foo") and a separate setter ("set-foo" for example) in source codes.
1. From the lexical point of view, "to foo" and "set-foo" are almost the same. "to foo" can even be considered a separate fancy word with a space in its name.
2. "set-foo" has a separate entry in a word list, but "to foo" has no its name token and execution token (in the general case [*]).
Some people consider the lack of a separate word as an advantage (as it reduces the overall number of headers), but this says about resources rather than using in source codes.
3. "set-foo" can be easily redefined (for example, if you want to check the assigned value to prevent some bugs in advance).
"to foo" *cannot* be redefined. Although, one can redefine "to" to check its argument and have a special action when its argument is "foo" — this is very cumbersome.
4. "set-foo" can be accessed using qualified names, such as
mymodule::set-foo or mymodule( set-foo )
A variant like "to mymodule::foo" could work,
a variant like "to mymodule( set-foo )" cannot work.
Bottom line: I don't see any advantages in *using* a to-based setter over a separate setter.
-- Ruvim