| Deutsch English Français Italiano |
|
<vnq10p$162l3$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Ruvim <ruvim.pinka@gmail.com> Newsgroups: comp.lang.forth Subject: Re: Back & Forth - Co-routines Date: Mon, 3 Feb 2025 13:07:36 +0400 Organization: A noiseless patient Spider Lines: 89 Message-ID: <vnq10p$162l3$1@dont-email.me> References: <nnd$2fb29a8e$298ef3f8@23fe4f00fa62d734> <49736c0ec0e34ca5d67f4e0d6e8cbe2a080e38ab@i2pn2.org> <vnkvvq$2a5o$1@dont-email.me> <nnd$14fbaf4d$1e462a10@60e007c2d8488e4d> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 03 Feb 2025 10:07:38 +0100 (CET) Injection-Info: dont-email.me; posting-host="0bba1a1e9d08f3d61dbdef812d50fa04"; logging-data="1247907"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1877tTB5e4Wt6+dBpDxbkhf" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:5FDzM92XO2QeAWP2ddbrkh3ZFqY= In-Reply-To: <nnd$14fbaf4d$1e462a10@60e007c2d8488e4d> Content-Language: en-US Bytes: 3410 On 2025-02-02 15:13, albert@spenarnc.xs4all.nl wrote: > In article <vnkvvq$2a5o$1@dont-email.me>, Ruvim <ruvim.pinka@gmail.com> wrote: >> 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. > > Nice catch! > > However, this is highly artificial. You have to have a recursive routine in this > vein: > > RECURSIVE > : fun .. fun ... fun . 'fun CATCH .. fun ... ; > > otherwise the global VARIABLE's can be ignored. > > I would be interested to see a remotely plausible example of this. > Mixing recursion and exception is ill advised by iq<160. Recursion is not necessary. It is enough to use the same-name "local" variables in different functions, some of which throw exceptions, and other catch exceptions. An artificial example: : local ( x2 addr1 -- ; R: nest-sys1 -- x1 addr1 nest-sys.xt nest-sys1 ) \ This definition assumes that nest-sys size is 1 cell, \ and xt is a subtype of nest-sys r> ( x2 addr nest-sys1 ) over dup @ >r >r [: 2r> ! ;] >r ( x2 addr1 nest-sys1 ) >r ! ; : idiv ( n1 n2\0 -- n3 | n1 0 -- never ) dup if / exit then -10 throw ; variable a variable b : foo ( n1 n2 -- ) b local a local a @ b @ idiv ." idiv result is " . cr ; : bar ( u1 -- u1 ) a local 100 a @ ['] foo catch if 2drop then a @ ; 0 bar . \ this must print 0, but will print 10 -- Ruvim