Sujet : Re: Back & Forth - Co-routines
De : no.email (at) *nospam* nospam.invalid (Paul Rubin)
Groupes : comp.lang.forthDate : 09. Feb 2025, 18:55:29
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87ed07vw8e.fsf@nightsong.com>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
The :}D means that the closure data is stored in the dictionary; there
is also :}L (for locals, deallocated when the surrounding definition
is exited), :}H (heap, deallocated with FREE-CLOSURE), and :}H1 (heap,
deallocated right after the first (and only) execution).
This is pretty cool, but it looks like quotations within the closure
aren't allowed to access the closure's locals, using them as OOP-like
state. In the current Gforth git snapshot:
: x [{: n :}d [: n 1+ dup to n ;] ;]h 0 execute ;
gives:
*the terminal*:26:30: error: Unsupported operation
: x [{: n :}d [: n 1+ dup to >>>n<<< ;] ;]h 0 execute ;
This is an attempt to make a counting function, like in Scheme:
(define (x)
((lambda (n)
(lambda ()
(set! n (+ 1 n))
n)) 0))
(define a (x))
(a) ; 1
(a) ; 2, etc.
It would be interesting if your conservative gc could be made reliable
and included with gforth, and then another suffix could be added to put
closure locals in the gc'd heap. "Reliable" = scan the return and
locals stacks, via suitable extensions added to GC. Also in a threaded
program I guess it would have to stop any threads that shared a GC'd
heap during collection of that heap.