Sujet : Re: Back & Forth - Co-routines
De : ruvim.pinka (at) *nospam* gmail.com (Ruvim)
Groupes : comp.lang.forthDate : 01. Feb 2025, 12:19:21
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vnkvvq$2a5o$1@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
On 2025-01-31 11:33, dxf wrote:
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 ;
15 3 divide a ? b ?
This approach does not work well with catch/throw. Because `throw` must restore the values of all "local" variables that are used in the definitions whose execution is being terminated. And this is difficult to implement.
See also 13.3.3.1, item c,
<
https://forth-standard.org/standard/locals#subsubsection.13.3.3.1>
| ABORT shall release all local storage resources,
| and CATCH / THROW (if implemented) shall release
| such resources for all definitions whose execution
| is being terminated.
-- Ruvim