Sujet : Re: Back & Forth - Co-routines
De : anton (at) *nospam* mips.complang.tuwien.ac.at (Anton Ertl)
Groupes : comp.lang.forthDate : 31. Jan 2025, 09:22:41
Autres entêtes
Organisation : Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID : <2025Jan31.092241@mips.complang.tuwien.ac.at>
References : 1 2
User-Agent : xrn 10.11
dxf <
dxforth@gmail.com> writes:
Not sure if previously mentioned but here's another version of LOCAL
>
: ;: >r ;
>
: LOCAL ( x adr -- )
r> -rot dup @ over 2>r ! ;: 2r> ! ;
>
variable A variable B 8 a ! 7 b !
>
: divide ( a b -- ) b local a local
a @ b @ / . cr ;
This kind of implementation leads to the same behaviour as dynamic
scoping. As long as you don't have quotations or other kinds of
nested definitions, or if you only access the locals of the innermost
definition (as in the quotations in the next standard draft), there is
no difference from static scoping. But if you have nested definitions
and access to outer locals, there is a difference, and Knuth's
man-or-boy test shows the difference. One usually wants static
scoping, but there are also cases where dynamic scoping is desired.
- 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/