| Deutsch English Français Italiano |
|
<vdu2b0$151ad$2@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.roellig-ltd.de!open-news-network.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Ruvim <ruvim.pinka@gmail.com>
Newsgroups: comp.lang.forth
Subject: value-flavoured properties of a word (was: value-flavoured
structures)
Date: Sun, 6 Oct 2024 17:12:00 +0400
Organization: A noiseless patient Spider
Lines: 175
Message-ID: <vdu2b0$151ad$2@dont-email.me>
References: <nnd$61e0ad9a$48ed61c2@b4d945e456041481>
<2024Sep13.200734@mips.complang.tuwien.ac.at> <66e4f98b$1@news.ausics.net>
<2024Sep14.081952@mips.complang.tuwien.ac.at> <vc6t1b$27sna$1@dont-email.me>
<2024Sep15.181634@mips.complang.tuwien.ac.at> <vd5pjl$kdp4$1@dont-email.me>
<2024Oct3.175858@mips.complang.tuwien.ac.at> <vdo4q8$4h5p$1@dont-email.me>
<2024Oct4.135221@mips.complang.tuwien.ac.at> <vdp0tf$80bg$1@dont-email.me>
<2024Oct4.200414@mips.complang.tuwien.ac.at> <vdr6k8$m1ue$1@dont-email.me>
<2024Oct5.175249@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 06 Oct 2024 15:12:02 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e46068a955d916fa6a0f28fb20080d2c";
logging-data="1213773"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18pWhCbWTnuBRyF3HHDKqCT"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Vsf++FVXEZQ3Rtct9krPu6d+ZlU=
In-Reply-To: <2024Oct5.175249@mips.complang.tuwien.ac.at>
Content-Language: en-US
Bytes: 5887
On 2024-10-05 19:52, Anton Ertl wrote:
> Ruvim <ruvim.pinka@gmail.com> writes:
>> On 2024-10-04 22:04, Anton Ertl wrote:
>>> Ruvim <ruvim.pinka@gmail.com> writes:
>>>> On 2024-10-04 15:52, Anton Ertl wrote:
>>>>> It can be defined: Gforth has SET-TO
>>> ...
>>>> I wonder why a kind of "TO" is not used to set this field/property, and
>>>> *maybe* a kind of "ACTION-OF" to get this property.
>>>
>>> Interesting idea. Maybe in some future version.
>
> Thinking some more about it, better not:
>
> SET-TO SET-OPTIMIZER etc. all work on the latest definition.
I assumed that there are methods under the hood that work on any given
definition, not the latest one. Or such methods could be defined.
> The methods that they set work on an NT or XT passed on the stack.
> The usual behaviour of defer-flavoured words is that the context is
> the same. If you have
>
> defer d
> ' foo is d
> action-of d
>
> That's always the same global D. For a defer-flavoured field,
> likewise:
>
> 0
> value: vf
> defer: df
> constant mystruct
>
> create foo mystruct allot
>
> 1 foo to vf
> ' . foo is df
>
> foo vf .
> 2 foo df
>
> So having TO TO instead of SET-TO would disobey this principle.
I see. I mean methods to access/change a property of any given word,
namely the "TO name run-time" semantics.
Let the *setter* for a word is an execution token that identifies "TO
name run-time" semantics for the word.
(I understand that in Gforth, the xt of a word is passed to the method
that implements "to", but I consider a simpler variant)
There are several approaches to access or assign the setter for a word.
1. "to-based" approach, but with special words instead of "is" and
"action-of".
\ setter-to ( xt.setter "name" -- )
\ setter-of ( "name" -- xt.setter )
\ Usage example
0 value foo
1 setter-of foo execute
foo . \ prints "1"
[: ( u -- )
dup 10 u> abort" too big value for x"
[ setter-of foo compiler, ]
;] setter-to foo
Disadvantages:
- a visually *unmarked* immediate argument in the input stream,
- inconvenient to work with nt.
2. "to-based" approach for structures
\ name>setter ( nt -- xt.setter )
\ to name>setter ( xt.setter nt -- )
\ Usage example
0 value foo
1 "foo" find-name name>setter execute
foo . \ prints "1"
[: ( u -- )
dup 10 u> abort" too big value for x"
[ "foo" find-name name>setter compiler, ]
;] "foo" find-name to name>setter
Disadvantages:
- a visually *unmarked* immediate argument in the input stream,
- the phrase `"foo" find-name to name>setter`
does look like we are storing an nt from `find-name` into `name>setter`.
(this is the same as for structures)
A solution for the latter: use another name instead of "to"
For example, "to-field"
"foo" find-name to-field name>setter
A solution for the former: mark the input argument. For example:
"foo" find-name to-field( name>setter )
3. Simple words
\ name>setter ( nt -- xt.setter )
\ name-setter! ( xt.setter nt -- )
\ Usage example
0 value foo
1 "foo" find-name name>setter execute
foo . \ prints "1"
[: ( u -- )
dup 10 u> abort" too big value for x"
[ "foo" find-name name>setter compiler, ]
;] "foo" find-name name-setter!
Disadvantages are unknown.
>
> For COMPILE, there is the additional problem that it is a deferred
> word, so when you do "IS COMPILE," you change the behaviour for all
> uses of "COMPILE,", not just of the latest definition. The actual
> method of each definition is called OPT-COMPILE,.
>
In the to-based approach, "compile," should behave like a field in a
structure.
Taking into account that an optimizer (or a special compiler) should be
associated with an xt (not with an nt), this could look as:
[: ( xt -- ) >body lit, ['] @ compile, ;]
' foo is compiler,
Or, with less disadvantages:
[: ( xt -- ) >body lit, ['] @ compile, ;]
' foo to-field( xt-compiler )
\ where
: compile, ( xt -- ) dup xt-compiler execute ;
All of the above are just ideas.
========== REMAINDER OF ARTICLE TRUNCATED ==========