Sujet : Re: Back & Forth - Co-routines
De : anton (at) *nospam* mips.complang.tuwien.ac.at (Anton Ertl)
Groupes : comp.lang.forthDate : 08. Feb 2025, 12:06:27
Autres entêtes
Organisation : Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID : <2025Feb8.120627@mips.complang.tuwien.ac.at>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : xrn 10.11
minforth@gmx.net (minforth) writes:
However, does this work in gforth?
>
: n+ ( n -- xt ) {: n :} [: n + ;] ;
5 n+ constant 5+
10 n+ constant 10+ ( 2nd instance )
2 5+ . ( 7 )
2 10+ . ( 12 )
3 5+ . ( 8 )
: n+ ( n -- xt ) [{: n :}d n + ;] ;
5 n+ constant 5+-xt
10 n+ constant 10+-xt
2 5+-xt execute . \ output: 7
2 10+-xt execute . \ output: 12
3 5+-xt execute . \ output: 8
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).
For the common cases of passing one cell or one double, or one FP
value to a closure, there are also pure-stack closures:
: n+ ( n -- xt ) [n:d + ;] ;
works just like the locals-using N+ above. We have several numbers
[T:A where T is the type (N for cell, D for double, F for float), and
A is the allocation (L for local, D for dictionary, H for heap,
currently no H1).
- anton
-- M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.htmlcomp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html New standard: https://forth-standard.org/EuroForth 2023 proceedings: http://www.euroforth.org/ef23/papers/EuroForth 2024 proceedings:
http://www.euroforth.org/ef24/papers/