| Deutsch English Français Italiano |
|
<nnd$3fcbe01d$4d253907@f2b3af8f84aa642f> View for Bookmarking (what is this?) Look up another Usenet article |
Newsgroups: comp.lang.forth
Subject: Re: Operator =?UTF-8?B?b3ZlcmxvYWRpbmc/?=
References: <a1aab44ee3b1b56c2f54f2606e98d040@www.novabbs.com> <2024Jul25.140858@mips.complang.tuwien.ac.at> <a0acecd6d9e2fd8067bf19c9050b1c15@www.novabbs.com> <2024Jul27.173555@mips.complang.tuwien.ac.at>
From: albert@spenarnc.xs4all.nl
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$3fcbe01d$4d253907@f2b3af8f84aa642f>
Organization: KPN B.V.
Date: Sat, 27 Jul 2024 22:55:48 +0200
Path: ...!2.eu.feeder.erje.net!feeder.erje.net!news.swapon.de!news.mixmin.net!feed.abavia.com!abe004.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 103
Injection-Date: Sat, 27 Jul 2024 22:55:48 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
Bytes: 4547
In article <2024Jul27.173555@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>minforth@gmx.net (minforth) writes:
>>On Thu, 25 Jul 2024 12:08:58 +0000, Anton Ertl wrote:
>>>>I am thinking on a much smaller scale i.e. unification of
>>>>operators for xVALUEs and xLOCALs. ANS Forth already has
>>>>overloaded TO but stops there.
>>>
>>> +TO is a common extension.
>>
>>Certainly. I have some array operations in mind, but they
>>are not relevant here. The principle is like
>>
>>: INIT { a }
>> [[: a ;]] \ read counter
>> [[: 1 +to a ;]] ; \ increment counter
>>DEFER count IS count
>>DEFER read IS read
>>5 INIT
>>COUNT COUNT READ -> should give 7
>
>My guess is that three lines here should be
>
>DEFER count
>DEFER read
>5 INIT IS count IS read
>
>>[[: ;]] define closures, but unlike gforth's more flexible
>>flat closures, they capture simply all upvalues (here local a).
>
>Gforth's flag closures can be considered lower-level (they come out of
>implementation ideas in the Scheme community) and are easier to
>implement, but emulating closures that capture outer locals is more
>cumbersome. One other aspect is that in Gforth's closures the
>programmer decides whether closures are allocated in the dictionary,
>on the locals stack, on the heap, or elsewhere. In the present case
>the dictionary seems to be a good place, and one can write this
>example as:
>
>: init ( a -- )
> align here >r , \ allocate a on the heap
> r@ [n:d @ ;] \ read counter
> r> [n:d 1 swap +! ;] \ increment counter
>;
>DEFER count
>DEFER read
>5 INIT IS count IS read
>count count read . \ prints "7 "
>
>INIT uses pure-stack closures [n:d consumes a value (in this exampl,
>the address of the cell containing A) from the stack at closure
>creation time and pushes it on the stack at closure run-time. Look,
>Ma, no locals:-).
>
>However, this does not use value-flavoured stuff, because we have to
>pass the address of A around, and then it's easier to use the
>variable-flavoured words. However, if you prefer the value-flavoured
>words, value-flavoured fields were recently added to Gforth and can be
>used to do that:
>
>begin-structure counter
> value: counter-val
>end-structure
>: init ( a -- )
> align here >r counter allot
> r@ to counter-val
> r@ [n:d counter-val ;]
> r> [n:d 1 swap +to counter-val ;]
>;
>DEFER count
>DEFER read
>5 INIT IS count IS read
>count count read . \ prints "7 "
>
>However, you still have to deal with the address explicitly, which
>becomes especially obvious in the counter closure.
>
>This raises the question of why you want to use closures for this
>task. Why not use one of the object-oriented Forth packages, some of
>which support value-flavoured fields (Mini-OOF2 among them AFAIK).
>
>>The code compiles unmodified for different types of a.
>>Incidentally, it compiles now with +TO, but realistically you
>>can't declare new 'op'TOs for too many different 'op' operators.
>
>This statement can be read in two different ways. I think there can
>be too many, but Stephen Pelc may think otherwise:-).
Also Marcel Hendrix thinks that. I count a dozen opTO's in tforth
and iforth.
Personnaly I hate TO and +TO, but if you decide to use them, you
could as well go all the way.
>
>- anton
Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat purring. - the Wise from Antrim -