Sujet : Re: Operator overloading?
De : minforth (at) *nospam* gmx.net (minforth)
Groupes : comp.lang.forthDate : 01. Aug 2024, 17:35:26
Autres entêtes
Organisation : novaBBS
Message-ID : <a2c90f7c95f277e6425db76aa996c2e3@www.novabbs.com>
References : 1 2 3 4 5 6 7 8
User-Agent : Rocksolid Light
On Thu, 1 Aug 2024 13:35:54 +0000, Anton Ertl wrote:
I don't know if this would be good enough for a Lisp/Scheme programmer,
but it works for my needs. And look Ma, no garbage collection. :-)
>
But then, with
>
| : 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
>
is A not gone after INIT is finished, and COUNT and READ will do ...
interesting things?
Of course not. When the compiler encounters the first [[: it lays
down code to capture the contents INIT's locals stack (environment)
when INIT is executed. All subsequent [[: "closures" are just
quotations which inject the captured stack segment into their own
locals stack, and update the captured environment when finished and
before their own locals stack is discarded.
In this way these "closure-flavoured quotations" see an updated A
i.e. shared upvalue, whenever one of them is called again. Execute
INIT a second time and the previously captured environment will be
overwritten.
The code is only a few lines long. I don't know if Pascal does
similar things, or if funarg problems are a show-stopper. And of
course this simple scheme is not OOP, but when it comes quasi for
free and is handy enough for small applications..