Sujet : Re: Operator overloading?
De : minforth (at) *nospam* gmx.net (minforth)
Groupes : comp.lang.forthDate : 27. Jul 2024, 13:10:28
Autres entêtes
Organisation : novaBBS
Message-ID : <a0acecd6d9e2fd8067bf19c9050b1c15@www.novabbs.com>
References : 1 2 3 4
User-Agent : Rocksolid Light
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
[[: ;]] define closures, but unlike gforth's more flexible
flat closures, they capture simply all upvalues (here local a).
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.