Sujet : Re: VALUE and TO implementation
De : ruvim.pinka (at) *nospam* gmail.com (Ruvim)
Groupes : comp.lang.forthDate : 04. Aug 2024, 11:09:42
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v8nk16$3vbpv$2@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
User-Agent : Mozilla Thunderbird
On 2024-08-04 13:38, mhx wrote:
On Sun, 4 Aug 2024 8:05:03 +0000, Paul Rubin wrote:
[..] I've sometimes thought of a version
of VALUE that makes two separate words, for reading and writing the
value:
>
17 XVALUE foo
>
creates two words, "?foo" and "!foo". ?foo pushes the value from foo
(initially 17) onto the stack. !foo moves TOS to foo.
That would work too, but apart from messing up Forth's unspoken
formatting guidelines, the scheme becomes impractical when you want to
propel additional messages like +TO, -TO, 'OF (returns address of),
0TO or CLEAR, SIZEOF and /OF . In practice, the latter two are used
very infrequently.
One problem of this OOP-like approach with many messages is that it works for a named object only, and does not work for an anonymous object on the stack.
In OOP, you can pass an object as parameter, and send messages to this object (or call its methods). But you cannot pass a value-flavored object as a parameter and then call its methods.
By the way, unlike value-flavored objects, a defer-flavored object can be passed as xt, and the methods `defer!`, `defer@`, and `execute` can be applied to this object.
In value-flavored structures approach the objects are anonymous and only passed as a stack parameter. But using "TO" is very confusing, because the immediate argument of "TO" is not an object name, but a class variable name (conceptually), and with object on the stack.
-- Ruvim