quotations and closures (was: Operator overloading?)

Liste des GroupesRevenir à cl forth 
Sujet : quotations and closures (was: Operator overloading?)
De : ruvim.pinka (at) *nospam* gmail.com (Ruvim)
Groupes : comp.lang.forth
Date : 30. Jul 2024, 20:32:05
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v8bf3m$142ge$1@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla Thunderbird
On 2024-07-27 22:16, minforth wrote:
On Sat, 27 Jul 2024 15:35:55 +0000, Anton Ertl wrote:
minforth@gmx.net (minforth) writes:
[[: ;]] define closures, but unlike gforth's more flexible
flat closures, they capture simply all upvalues (here local a).
>
Gforth's flag closures can be considered lower-level (they come out of
implementation ideas in the Scheme community) and are easier to
implement, but emulating closures that capture outer locals is more
cumbersome.
 In MF36 quotations already have read/write access to the locals of the
parent function.
I think, the standard quotation (that is defined via "[: ... ;]") shall return the same xt in different runs in run-time.
For example, the following word "foo":
   : foo ( -- xt ) [: bar ;] ;
is a constant, as it always returns the same xt.
Therefore, it's better to throw an exception if an external local variable is referenced in a standard quotation.
If a local variable can be referenced in a nested definition (and the funarg problem is solved), it's better to call that definition a "closure" rather than a "quotation".

So closures became a simple by-product through capturing
the parent's locals stack and injecting it at startup during closure
runtime. When the closure finishes, the captured stack is simply
updated.
 I don't know if this would be good enough for a Lisp/Scheme programmer,
but it works for my needs. And look Ma, no garbage collection. :-)
 
One other aspect is that in Gforth's closures the
programmer decides whether closures are allocated in the dictionary,
on the locals stack, on the heap, or elsewhere.
 In MF36 it is only the locals stack. AFAIU in other programming
languagues there are closures where the parent function can be seen as
constructor. IOW call the parent function twice and you get different
xts/addresses. From this perspective MF36 closures would perhaps only
qualify as 'half-closures'.
A related problem is known as the funarg problem [1].
I can guess, the upwards funarg problem is not solved in MF36.
Concerning the downwards funarg problem — is it solved for the cases when the enclosing function is called recursively (directly or indirectly)?
A dumb testcase:
   : t1 ( u xt -- u )
     {: k xt :}
     k 0= if 0 exit then
     k 1-  [[: k ;]]  dup >r recurse r> execute +
     xt if xt execute + then
   ;
   t{ 0 0 t1 -> 0 }t
   t{ 1 0 t1 -> 1 }t
   t{ 2 0 t1 -> 5 }t
   t{ 3 0 t1 -> 11 }t
[1] https://en.wikipedia.org/wiki/Funarg_problem
--
Ruvim

Date Sujet#  Auteur
25 Jul 24 * Operator overloading?78minforth
25 Jul 24 +- Re: Operator overloading?1dxf
25 Jul 24 +* Re: Operator overloading?18Michael Raitza
25 Jul 24 i`* Re: Operator overloading?17minforth
25 Jul 24 i +* Re: Operator overloading?5mhx
25 Jul 24 i i`* Re: Operator overloading?4minforth
26 Jul 24 i i `* Re: Operator overloading?3minforth
26 Jul 24 i i  `* Re: Operator overloading?2mhx
26 Jul 24 i i   `- Re: Operator overloading?1minforth
25 Jul 24 i `* Re: Operator overloading?11Anton Ertl
25 Jul 24 i  +* Re: Operator overloading?2minforth
30 Jul 24 i  i`- Re: Operator overloading?1Ruvim
27 Jul 24 i  `* Re: Operator overloading?8minforth
27 Jul 24 i   `* Re: Operator overloading?7Anton Ertl
27 Jul 24 i    +* Re: Operator overloading?4minforth
30 Jul 24 i    i+- quotations and closures (was: Operator overloading?)1Ruvim
1 Aug 24 i    i`* Re: Operator overloading?2Anton Ertl
1 Aug 24 i    i `- Re: Operator overloading?1minforth
27 Jul 24 i    `* Re: Operator overloading?2albert
29 Jul 24 i     `- Re: Operator overloading?1minforth
26 Jul 24 +- Re: Operator overloading?1Jan Coombs
30 Jul 24 `* Re: Operator overloading?57Stephen Pelc
30 Jul 24  +* Re: Operator overloading?3minforth
30 Jul 24  i+- Re: Operator overloading?1Stephen Pelc
1 Aug 24  i`- Re: Operator overloading?1Anton Ertl
31 Jul 24  `* Re: Operator overloading?53albert
31 Jul 24   `* Re: Operator overloading?52Gerry Jackson
31 Jul 24    +* Re: Operator overloading?50mhx
31 Jul 24    i+* Re: Operator overloading?3minforth
31 Jul 24    ii`* Re: Operator overloading?2mhx
31 Jul 24    ii `- Re: Operator overloading?1mhx
31 Jul 24    i+* VALUE and TO implementation (was: Operator overloading?)45Ruvim
31 Jul 24    ii+* Re: VALUE and TO implementation (was: Operator overloading?)41Anton Ertl
1 Aug 24    iii`* Re: VALUE and TO implementation40Ruvim
1 Aug 24    iii `* Re: VALUE and TO implementation39Anton Ertl
2 Aug 24    iii  `* Re: VALUE and TO implementation38Ruvim
3 Aug 24    iii   +* Re: VALUE and TO implementation35minforth
3 Aug 24    iii   i+* Re: VALUE and TO implementation33Ruvim
3 Aug 24    iii   ii`* Re: VALUE and TO implementation32minforth
4 Aug 24    iii   ii `* Re: VALUE and TO implementation31Ruvim
4 Aug 24    iii   ii  `* Re: VALUE and TO implementation30mhx
4 Aug 24    iii   ii   +* Re: VALUE and TO implementation4Paul Rubin
4 Aug 24    iii   ii   i+* Re: VALUE and TO implementation2mhx
4 Aug 24    iii   ii   ii`- Re: VALUE and TO implementation1Ruvim
4 Aug 24    iii   ii   i`- Re: VALUE and TO implementation1Ruvim
4 Aug 24    iii   ii   +- Re: VALUE and TO implementation1Anton Ertl
4 Aug 24    iii   ii   +* Alternative for long parsing words (was: VALUE and TO implementation)9Ruvim
5 Aug 24    iii   ii   i`* Re: Alternative for long parsing words (was: VALUE and TO implementation)8albert
5 Aug 24    iii   ii   i `* Re: Alternative for long parsing words7Ruvim
5 Aug 24    iii   ii   i  +* Re: Alternative for long parsing words5Anton Ertl
6 Aug 24    iii   ii   i  i+* Re: Alternative for long parsing words2Ruvim
6 Aug 24    iii   ii   i  ii`- Re: Alternative for long parsing words1mhx
6 Aug 24    iii   ii   i  i`* Re: Alternative for long parsing words2Ruvim
9 Aug 24    iii   ii   i  i `- Re: Alternative for long parsing words1Ruvim
6 Aug 24    iii   ii   i  `- Re: Alternative for long parsing words1albert
5 Aug 24    iii   ii   +- Re: VALUE and TO implementation1Stephen Pelc
5 Aug 24    iii   ii   `* Re: VALUE and TO implementation14dxf
5 Aug 24    iii   ii    `* Re: VALUE and TO implementation13mhx
5 Aug 24    iii   ii     +* Re: VALUE and TO implementation10dxf
5 Aug 24    iii   ii     i`* Re: VALUE and TO implementation9Ruvim
6 Aug 24    iii   ii     i `* Re: VALUE and TO implementation8dxf
7 Aug 24    iii   ii     i  `* Re: VALUE and TO implementation7dxf
7 Aug 24    iii   ii     i   +* Re: VALUE and TO implementation3Anton Ertl
7 Aug 24    iii   ii     i   i+- Re: VALUE and TO implementation1dxf
7 Aug 24    iii   ii     i   i`- Interpretation semantics (was: VALUE and TO implementation)1Ruvim
7 Aug 24    iii   ii     i   `* Re: VALUE and TO implementation3albert
7 Aug 24    iii   ii     i    `* Re: VALUE and TO implementation2Paul Rubin
8 Aug 24    iii   ii     i     `- Re: VALUE and TO implementation1albert
5 Aug 24    iii   ii     `* Re: VALUE and TO implementation2Anton Ertl
6 Aug 24    iii   ii      `- Re: VALUE and TO implementation1albert
3 Aug 24    iii   i`- Re: VALUE and TO implementation1Anton Ertl
3 Aug 24    iii   `* Re: VALUE and TO implementation2mhx
4 Aug 24    iii    `- Re: VALUE and TO implementation1Ruvim
1 Aug 24    ii+* Re: VALUE and TO implementation2minforth
2 Aug 24    iii`- Re: VALUE and TO implementation1albert
1 Aug 24    ii`- Re: VALUE and TO implementation1Ruvim
31 Jul 24    i`- Re: Operator overloading?1Gerry Jackson
31 Jul 24    `- Re: Operator overloading?1Anton Ertl

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal