Re: Back & Forth - Co-routines

Liste des Groupes 
Sujet : Re: Back & Forth - Co-routines
De : ruvim.pinka (at) *nospam* gmail.com (Ruvim)
Groupes : comp.lang.forth
Date : 03. Feb 2025, 10:07:36
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vnq10p$162l3$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
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

Date Sujet#  Auteur
31 Jan 25 * Re: Back & Forth - Co-routines91dxf
31 Jan 25 +- Re: Back & Forth - Co-routines1Anton Ertl
31 Jan 25 +- Re: Back & Forth - Co-routines1albert
31 Jan 25 +* Re: Back & Forth - Co-routines14Hans Bezemer
1 Feb 25 i`* Re: Back & Forth - Co-routines13dxf
1 Feb 25 i `* Re: Back & Forth - Co-routines12Anton Ertl
1 Feb 25 i  +* Re: Back & Forth - Co-routines4dxf
1 Feb 25 i  i+- Re: Back & Forth - Co-routines1albert
1 Feb 25 i  i`* Re: Back & Forth - Co-routines2Anton Ertl
2 Feb 25 i  i `- Re: Back & Forth - Co-routines1dxf
2 Feb 25 i  `* Re: Use of { and } was Re: Back & Forth - Co-routines7dxf
2 Feb 25 i   `* Re: Use of { and } was Re: Back & Forth - Co-routines6Anton Ertl
2 Feb 25 i    +- Re: Use of { and } was Re: Back & Forth - Co-routines1dxf
2 Feb 25 i    +* Re: Use of { and } was Re: Back & Forth - Co-routines2Anton Ertl
2 Feb 25 i    i`- Re: Use of { and } was Re: Back & Forth - Co-routines1Bernd Linsel
6 Feb 25 i    `* Re: Use of { and } was Re: Back & Forth - Co-routines2Waldek Hebisch
6 Feb 25 i     `- Re: Use of { and } was Re: Back & Forth - Co-routines1dxf
1 Feb 25 +* Re: Back & Forth - Co-routines70Ruvim
2 Feb 25 i+- Re: Back & Forth - Co-routines1dxf
2 Feb 25 i+* Re: Back & Forth - Co-routines2Paul Rubin
3 Feb 25 ii`- Re: Back & Forth - Co-routines1dxf
3 Feb 25 i`* Re: Back & Forth - Co-routines66Ruvim
3 Feb 25 i +* Re: Back & Forth - Co-routines57albert
3 Feb 25 i i`* Re: Back & Forth - Co-routines56Paul Rubin
4 Feb 25 i i `* Re: Back & Forth - Co-routines55albert
6 Feb 25 i i  +* Re: Back & Forth - Co-routines2HenryHH
6 Feb 25 i i  i`- Re: Back & Forth - Co-routines1albert
6 Feb 25 i i  `* Re: Back & Forth - Co-routines52minforth
6 Feb 25 i i   +* Re: Back & Forth - Co-routines2albert
6 Feb 25 i i   i`- Re: Back & Forth - Co-routines1minforth
6 Feb 25 i i   `* Re: Back & Forth - Co-routines49Anton Ertl
6 Feb 25 i i    `* Re: Back & Forth - Co-routines48minforth
6 Feb 25 i i     +* Re: Back & Forth - Co-routines19dxf
6 Feb 25 i i     i+* Re: Back & Forth - Co-routines2minforth
7 Feb 25 i i     ii`- Re: Back & Forth - Co-routines1sjack
6 Feb 25 i i     i`* Re: Back & Forth - Co-routines16Anton Ertl
6 Feb 25 i i     i +- Re: Back & Forth - Co-routines1minforth
7 Feb 25 i i     i `* Re: Back & Forth - Co-routines14dxf
7 Feb 25 i i     i  +* Re: Back & Forth - Co-routines2minforth
7 Feb 25 i i     i  i`- Re: Back & Forth - Co-routines1dxf
8 Feb 25 i i     i  `* quotations (was: Back & Forth - Co-routines)11Anton Ertl
9 Feb 25 i i     i   +* Re: quotations9dxf
9 Feb 25 i i     i   i+* Re: quotations4Paul Rubin
9 Feb 25 i i     i   ii`* Re: quotations3dxf
9 Feb 25 i i     i   ii `* Re: quotations2Paul Rubin
9 Feb 25 i i     i   ii  `- Re: quotations1minforth
9 Feb 25 i i     i   i`* Re: quotations4Anton Ertl
9 Feb 25 i i     i   i +- Re: quotations1albert
10 Feb 25 i i     i   i `* Re: quotations2dxf
10 Feb 25 i i     i   i  `- Re: quotations1albert
9 Feb 25 i i     i   `- Re: quotations (was: Back & Forth - Co-routines)1albert
6 Feb 25 i i     +* Re: Back & Forth - Co-routines27Anton Ertl
6 Feb 25 i i     i+- Re: Back & Forth - Co-routines1minforth
7 Feb 25 i i     i`* Re: Back & Forth - Co-routines25minforth
8 Feb 25 i i     i `* Re: Back & Forth - Co-routines24Anton Ertl
8 Feb 25 i i     i  +* Re: Back & Forth - Co-routines4minforth
9 Feb 25 i i     i  i`* Re: Back & Forth - Co-routines3Paul Rubin
9 Feb 25 i i     i  i +- Re: Back & Forth - Co-routines1minforth
9 Feb 25 i i     i  i `- Re: Back & Forth - Co-routines1Anton Ertl
9 Feb 25 i i     i  `* Re: Back & Forth - Co-routines19Paul Rubin
9 Feb 25 i i     i   +* Re: Back & Forth - Co-routines3minforth
9 Feb 25 i i     i   i`* Re: Back & Forth - Co-routines2Paul Rubin
10 Feb 25 i i     i   i `- Re: Back & Forth - Co-routines1minforth
10 Feb 25 i i     i   `* Re: Back & Forth - Co-routines15Anton Ertl
10 Feb 25 i i     i    +* Re: Back & Forth - Co-routines8ahmed
10 Feb 25 i i     i    i`* Re: Back & Forth - Co-routines7Anton Ertl
10 Feb 25 i i     i    i +- Re: Back & Forth - Co-routines1ahmed
10 Feb 25 i i     i    i +- Re: Back & Forth - Co-routines1minforth
10 Feb 25 i i     i    i +* Re: Back & Forth - Co-routines3mhx
10 Feb 25 i i     i    i i+- Re: Back & Forth - Co-routines1albert
10 Feb 25 i i     i    i i`- Re: Back & Forth - Co-routines1Paul Rubin
10 Feb 25 i i     i    i `- Re: Back & Forth - Co-routines1albert
10 Feb 25 i i     i    `* Re: Back & Forth - Co-routines6Paul Rubin
11 Feb 25 i i     i     `* Re: Back & Forth - Co-routines5minforth
11 Feb 25 i i     i      `* Re: Back & Forth - Co-routines4Paul Rubin
12 Feb 25 i i     i       +- Re: Back & Forth - Co-routines1albert
12 Feb 25 i i     i       `* Re: Back & Forth - Co-routines2minforth
14 Feb 25 i i     i        `- Multi-Tasking (was: Back & Forth - Co-routines)1Anton Ertl
7 Feb 25 i i     `- Re: Back & Forth - Co-routines1minforth
22 Mar 25 i `* Re: Back & Forth - Co-routines8sjack
23 Mar 25 i  `* Re: Back & Forth - Co-routines7dxf
23 Mar 25 i   +* Re: Back & Forth - Co-routines2sjack
24 Mar 25 i   i`- Re: Back & Forth - Co-routines1sjack
24 Mar 25 i   +- Re: Back & Forth - Co-routines1sjack
24 Mar 25 i   `* Re: Back & Forth - Co-routines3dxf
24 Mar 25 i    `* Re: Back & Forth - Co-routines2dxf
24 Mar 25 i     `- Re: Back & Forth - Co-routines1dxf
11 Mar 25 `* Re: Back & Forth - Co-routines4dxf
21 Mar 25  `* Re: Back & Forth - Co-routines3dxf
21 Mar 25   `* Re: Back & Forth - Co-routines2dxf
22 Mar 25    `- Re: Back & Forth - Co-routines1dxf

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal