Re: Back & Forth - Co-routines

Liste des GroupesRevenir à cl forth 
Sujet : Re: Back & Forth - Co-routines
De : anton (at) *nospam* mips.complang.tuwien.ac.at (Anton Ertl)
Groupes : comp.lang.forth
Date : 06. Feb 2025, 18:20:51
Autres entêtes
Organisation : Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID : <2025Feb6.182051@mips.complang.tuwien.ac.at>
References : 1 2 3 4 5 6 7 8 9
User-Agent : xrn 10.11
dxf <dxforth@gmail.com> writes:
On 7/02/2025 12:59 am, minforth wrote:
On Thu, 6 Feb 2025 12:57:12 +0000, Anton Ertl wrote:
AFAIR 200x nested definitions were justified on the grounds named
definitions were neither needed nor wanted

Really?  There's a proposal to eliminate named definitions?  That's
news to me.

There are cases where you need to pass an xt to some word, and where
the xt does not merit a name, e.g.,

: (where) ( "name" -- ) \ gforth-internal
    (') [: over = ;] forwheres
    drop -1 where-index ! ;

Of course, one could do that without quotations:

: (where-helper) over = ;

: (where) ( "name" -- ) \ gforth-internal
    (') ['] (where-helper) forwheres
    drop -1 where-index ! ;

But it's more convenient and readable with quotations.

and access to external
locals not necessary.

It's more that anything proper is pretty hard to implement and there
was not enough demand for that nor existing practice that anybody
wanted to propose for standardization.

However, the topic came up repeatedly in discussions, so in 2018 I sat
down to investigate the issue.  After a while I had a paper design,
but had my doubts that it is worth implementing it.  I let Bernd
Paysan read the paper, and he came up with further simplifications and
implemented the result; the changes were so deep that I had to mostly
rewrite the paper, resulting in our EuroForth 2018 paper
[ertl&paysan18].  And Bernd embraced using the resulting closures.

I still had my doubts about whether one really needs that, as I had
not found a short example that showed a clear advantage over the
alternatives.  I asked Niklaus Wirth, who had kept access to outer
locals in his languages for many decades, but his answer was that he
finally removed that feature from Oberon 07 in 2013, and he did not
provide such an example, either.

Finally, such a usage was found by Bernd Paysan: He had implemented a
variant of the actor model
<https://gforth.org/manual/Message-queues.html> (inspired by Heinz
Schnitter's Open Network Forth):

One task sends a message consisting of an xt to another task, and the
other task then executes it.  But sending just an xt without any data
is not very useful, so one could also send integers, strings, etc.
The sender would send the data and then the xt, and the receiving task
would push the data on the stack, and then execute the xt.  However,
several tasks can send messages to one task at the same time, so there
was some additional twist to avoid mixing the parts of a message of
one task with the parts of a message of another task.  With closures
that all became unnecessary: The data is part of the passed xt.

Another development was pure-stack closures.

But none of this existed when quotations were accepted for
standardization.

@InProceedings{ertl&paysan18,
  author =       {M. Anton Ertl and Bernd Paysan},
  title =        {Closures --- the {Forth} way},
  crossref =     {euroforth18},
  pages =        {17--30},
  url =          {https://www.complang.tuwien.ac.at/papers/ertl%26paysan.pdf},
  url2 =         {http://www.euroforth.org/ef18/papers/ertl.pdf},
  slides-url =   {http://www.euroforth.org/ef18/papers/ertl-slides.pdf},
  video = {https://wiki.forth-ev.de/doku.php/events:ef2018:closures},
  OPTnote =      {refereed},
  abstract =     {In Forth 200x, a quotation cannot access a local
                  defined outside it, and therefore cannot be
                  parameterized in the definition that produces its
                  execution token.  We present Forth closures; they
                  lift this restriction with minimal implementation
                  complexity.  They are based on passing parameters on
                  the stack when producing the execution token.  The
                  programmer has to explicitly manage the memory of
                  the closure.  We show a number of usage examples.
                  We also present the current implementation, which
                  takes 109~source lines of code (including some extra
                  features).  The programmer can mechanically convert
                  lexical scoping (accessing a local defined outside)
                  into code using our closures, by applying assignment
                  conversion and flat-closure conversion.  The result
                  can do everything one expects from closures,
                  including passing Knuth's man-or-boy test and living
                  beyond the end of their enclosing definitions.}
}

- anton
--
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.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/

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