Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Radioactive cats have 18 half-lives.


devel / comp.lang.forth / Re: locals and pure-stack closures (was: GOTO and LABEL ...)

SubjectAuthor
* GOTO and LABEL / CONTINUE and BREAKminf...@arcor.de
+* Re: GOTO and LABEL / CONTINUE and BREAKRuvim
|`* Re: GOTO and LABEL / CONTINUE and BREAKminf...@arcor.de
| +* Re: GOTO and LABEL / CONTINUE and BREAKRuvim
| |`* Re: GOTO and LABEL / CONTINUE and BREAKMarcel Hendrix
| | +* Re: GOTO and LABEL / CONTINUE and BREAKRuvim
| | |`* Re: GOTO and LABEL / CONTINUE and BREAKMarcel Hendrix
| | | `- Re: GOTO and LABEL / CONTINUE and BREAKRuvim
| | `* Re: GOTO and LABEL / CONTINUE and BREAKPaul Rubin
| |  `- Re: GOTO and LABEL / CONTINUE and BREAKMarcel Hendrix
| `* Re: GOTO and LABEL / CONTINUE and BREAKHans Bezemer
|  +* Re: GOTO and LABEL / CONTINUE and BREAKminf...@arcor.de
|  |`* Re: GOTO and LABEL / CONTINUE and BREAKdxforth
|  | `* Re: GOTO and LABEL / CONTINUE and BREAKminf...@arcor.de
|  |  `- Re: GOTO and LABEL / CONTINUE and BREAKdxforth
|  `* Re: GOTO and LABEL / CONTINUE and BREAKdxforth
|   `* Re: GOTO and LABEL / CONTINUE and BREAKAnton Ertl
|    `- Re: GOTO and LABEL / CONTINUE and BREAKdxforth
+* Re: GOTO and LABEL / CONTINUE and BREAKAnton Ertl
|`- Re: GOTO and LABEL / CONTINUE and BREAKminf...@arcor.de
+- Re: GOTO and LABEL / CONTINUE and BREAKHeinrich Hohl
+* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
|+* Re: GOTO and LABEL / CONTINUE and BREAKminf...@arcor.de
||+* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
|||+* Re: GOTO and LABEL / CONTINUE and BREAKminf...@arcor.de
||||`- Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
|||`* Re: GOTO and LABEL / CONTINUE and BREAKPaul Rubin
||| +* Re: GOTO and LABEL / CONTINUE and BREAKdxforth
||| |`* Re: GOTO and LABEL / CONTINUE and BREAKdxforth
||| | +* Re: GOTO and LABEL / CONTINUE and BREAKdxforth
||| | |`- Re: GOTO and LABEL / CONTINUE and BREAKminforth
||| | `* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |  +* Re: GOTO and LABEL / CONTINUE and BREAKRuvim
||| |  |`* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |  | `* Re: GOTO and LABEL / CONTINUE and BREAKRuvim
||| |  |  `- Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |  +* Re: GOTO and LABEL / CONTINUE and BREAKnone
||| |  |`* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |  | `* Re: GOTO and LABEL / CONTINUE and BREAKnone
||| |  |  `* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |  |   `* Re: GOTO and LABEL / CONTINUE and BREAKnone
||| |  |    `* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |  |     `* Re: GOTO and LABEL / CONTINUE and BREAKnone
||| |  |      `- Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |  `* Re: GOTO and LABEL / CONTINUE and BREAKdxforth
||| |   +* Re: GOTO and LABEL / CONTINUE and BREAKAnton Ertl
||| |   |`- Re: GOTO and LABEL / CONTINUE and BREAKdxforth
||| |   `* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |    `* Re: GOTO and LABEL / CONTINUE and BREAKdxforth
||| |     `* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |      +- Re: GOTO and LABEL / CONTINUE and BREAKdxforth
||| |      `* Re: GOTO and LABEL / CONTINUE and BREAKBrian Fox
||| |       +* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |       |`* Re: GOTO and LABEL / CONTINUE and BREAKBrian Fox
||| |       | +- Re: GOTO and LABEL / CONTINUE and BREAKBrian Fox
||| |       | `* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |       |  `* Re: GOTO and LABEL / CONTINUE and BREAKBrian Fox
||| |       |   +* Re: GOTO and LABEL / CONTINUE and BREAKMarcel Hendrix
||| |       |   |+- Re: GOTO and LABEL / CONTINUE and BREAKBrian Fox
||| |       |   |+* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |       |   ||+- Re: GOTO and LABEL / CONTINUE and BREAKminforth
||| |       |   ||`* Re: GOTO and LABEL / CONTINUE and BREAKnone
||| |       |   || +* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |       |   || |`* Re: GOTO and LABEL / CONTINUE and BREAKnone
||| |       |   || | `- Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |       |   || `* Re: GOTO and LABEL / CONTINUE and BREAKAnton Ertl
||| |       |   ||  +* Re: GOTO and LABEL / CONTINUE and BREAKnone
||| |       |   ||  |`* Re: GOTO and LABEL / CONTINUE and BREAKAnton Ertl
||| |       |   ||  | +* Re: GOTO and LABEL / CONTINUE and BREAKTravis Bemann
||| |       |   ||  | |+- Re: GOTO and LABEL / CONTINUE and BREAKTravis Bemann
||| |       |   ||  | |`* Re: GOTO and LABEL / CONTINUE and BREAKminforth
||| |       |   ||  | | `* Re: GOTO and LABEL / CONTINUE and BREAKTravis Bemann
||| |       |   ||  | |  +- Re: GOTO and LABEL / CONTINUE and BREAKminforth
||| |       |   ||  | |  `* Re: GOTO and LABEL / CONTINUE and BREAKdxforth
||| |       |   ||  | |   `* Re: GOTO and LABEL / CONTINUE and BREAKTravis Bemann
||| |       |   ||  | |    +* Re: GOTO and LABEL / CONTINUE and BREAKdxforth
||| |       |   ||  | |    |`* locals and pure-stack closures (was: GOTO and LABEL ...)Anton Ertl
||| |       |   ||  | |    | +* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Travis Bemann
||| |       |   ||  | |    | |+* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Travis Bemann
||| |       |   ||  | |    | ||`* Re: locals and pure-stack closures (was: GOTO and LABEL ...)fabianor...@gmail.com
||| |       |   ||  | |    | || `* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Travis Bemann
||| |       |   ||  | |    | ||  `- Re: locals and pure-stack closures (was: GOTO and LABEL ...)Travis Bemann
||| |       |   ||  | |    | |`* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Anton Ertl
||| |       |   ||  | |    | | +* Re: locals and pure-stack closures (was: GOTO and LABEL ...)minforth
||| |       |   ||  | |    | | |`- Re: locals and pure-stack closures (was: GOTO and LABEL ...)Anton Ertl
||| |       |   ||  | |    | | `- Re: locals and pure-stack closures (was: GOTO and LABEL ...)Travis Bemann
||| |       |   ||  | |    | +* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Ruvim
||| |       |   ||  | |    | |+* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Ruvim
||| |       |   ||  | |    | ||+* Re: locals and pure-stack closures (was: GOTO and LABEL ...)minforth
||| |       |   ||  | |    | |||`* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Anton Ertl
||| |       |   ||  | |    | ||| `* Re: locals and pure-stack closures (was: GOTO and LABEL ...)minforth
||| |       |   ||  | |    | |||  `* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Travis Bemann
||| |       |   ||  | |    | |||   `* Re: locals and pure-stack closures (was: GOTO and LABEL ...)minforth
||| |       |   ||  | |    | |||    `* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Travis Bemann
||| |       |   ||  | |    | |||     `* Re: locals and pure-stack closures (was: GOTO and LABEL ...)minforth
||| |       |   ||  | |    | |||      `* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Travis Bemann
||| |       |   ||  | |    | |||       +- Re: locals and pure-stack closures (was: GOTO and LABEL ...)Travis Bemann
||| |       |   ||  | |    | |||       `- Re: locals and pure-stack closures (was: GOTO and LABEL ...)minforth
||| |       |   ||  | |    | ||`* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Anton Ertl
||| |       |   ||  | |    | || `* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Ruvim
||| |       |   ||  | |    | ||  +* Re: locals and pure-stack closures (was: GOTO and LABEL ...)minforth
||| |       |   ||  | |    | ||  `* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Anton Ertl
||| |       |   ||  | |    | |`* Re: locals and pure-stack closures (was: GOTO and LABEL ...)Anton Ertl
||| |       |   ||  | |    | `- Re: locals and pure-stack closures (was: GOTO and LABEL ...)dxforth
||| |       |   ||  | |    `- Re: GOTO and LABEL / CONTINUE and BREAKfabianor...@gmail.com
||| |       |   ||  | `* Re: GOTO and LABEL / CONTINUE and BREAKnone
||| |       |   ||  `- Re: GOTO and LABEL / CONTINUE and BREAKdxforth
||| |       |   |`* Re: GOTO and LABEL / CONTINUE and BREAKAnton Ertl
||| |       |   +- Re: GOTO and LABEL / CONTINUE and BREAKBrian Fox
||| |       |   +- Re: GOTO and LABEL / CONTINUE and BREAKJan Coombs
||| |       |   `* Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| |       +- Re: GOTO and LABEL / CONTINUE and BREAKdxforth
||| |       `* Re: GOTO and LABEL / CONTINUE and BREAKminforth
||| +- Re: GOTO and LABEL / CONTINUE and BREAKLorem Ipsum
||| `* Re: GOTO and LABEL / CONTINUE and BREAKMarcel Hendrix
||`* Re: GOTO and LABEL / CONTINUE and BREAKAndy Valencia
|`- Re: GOTO and LABEL / CONTINUE and BREAKdxforth
+- Re: GOTO and LABEL / CONTINUE and BREAKnone
`* Re: GOTO and LABEL / CONTINUE and BREAKminforth

Pages:123456
Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<2023Apr7.141532@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23168&group=comp.lang.forth#23168

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
Date: Fri, 07 Apr 2023 12:15:32 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 12
Message-ID: <2023Apr7.141532@mips.complang.tuwien.ac.at>
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com> <c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com> <u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com> <u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at> <u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me> <95f20fc4-4135-4c8e-895e-2f7d4ff90124n@googlegroups.com>
Injection-Info: dont-email.me; posting-host="47321a2d7491f360f53f7cdf88144d7a";
logging-data="868090"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/gHbUK+MUHyQOM6JrRcIs"
Cancel-Lock: sha1:oyc2/nInWDO4w80kGgmcdzQjNzI=
X-newsreader: xrn 10.11
 by: Anton Ertl - Fri, 7 Apr 2023 12:15 UTC

minforth <minforth@arcor.de> writes:
>But I am still struggling with finding good applications

Don't struggle! If the need does not come to you on its own, you
don't need them.

- 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 2022: https://euro.theforth.net

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<2f4509f4-db29-410b-88c1-77027af76a04n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23169&group=comp.lang.forth#23169

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ad4:4ba2:0:b0:56f:18ed:316f with SMTP id i2-20020ad44ba2000000b0056f18ed316fmr560194qvw.1.1680872893575;
Fri, 07 Apr 2023 06:08:13 -0700 (PDT)
X-Received: by 2002:a05:620a:4415:b0:745:70ea:4fe6 with SMTP id
v21-20020a05620a441500b0074570ea4fe6mr430965qkp.6.1680872892743; Fri, 07 Apr
2023 06:08:12 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 7 Apr 2023 06:08:12 -0700 (PDT)
In-Reply-To: <2023Apr7.141532@mips.complang.tuwien.ac.at>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f11:fd69:782e:aff5:eac0:ad07;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f11:fd69:782e:aff5:eac0:ad07
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me>
<95f20fc4-4135-4c8e-895e-2f7d4ff90124n@googlegroups.com> <2023Apr7.141532@mips.complang.tuwien.ac.at>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2f4509f4-db29-410b-88c1-77027af76a04n@googlegroups.com>
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
From: minfo...@arcor.de (minforth)
Injection-Date: Fri, 07 Apr 2023 13:08:13 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2008
 by: minforth - Fri, 7 Apr 2023 13:08 UTC

Anton Ertl schrieb am Freitag, 7. April 2023 um 14:17:54 UTC+2:
> minforth <minf...@arcor.de> writes:
> >But I am still struggling with finding good applications
> Don't struggle! If the need does not come to you on its own, you
> don't need them.

That zero investment so far suits me well. ;-)

"Look, Ma, I have a clever solution! All I need now is a nice problem!"

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<dbb59818-1b25-414d-87e9-a365673ac072n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23170&group=comp.lang.forth#23170

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:d89:b0:745:6afc:9bb2 with SMTP id q9-20020a05620a0d8900b007456afc9bb2mr538740qkl.14.1680885486645;
Fri, 07 Apr 2023 09:38:06 -0700 (PDT)
X-Received: by 2002:a05:622a:1998:b0:3e4:db08:ae9c with SMTP id
u24-20020a05622a199800b003e4db08ae9cmr913865qtc.8.1680885486444; Fri, 07 Apr
2023 09:38:06 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 7 Apr 2023 09:38:06 -0700 (PDT)
In-Reply-To: <2f4509f4-db29-410b-88c1-77027af76a04n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=165.156.39.57; posting-account=Crnq4woAAABK99A43gBY5KlP3EUyAJAK
NNTP-Posting-Host: 165.156.39.57
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me>
<95f20fc4-4135-4c8e-895e-2f7d4ff90124n@googlegroups.com> <2023Apr7.141532@mips.complang.tuwien.ac.at>
<2f4509f4-db29-410b-88c1-77027af76a04n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <dbb59818-1b25-414d-87e9-a365673ac072n@googlegroups.com>
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
From: tabem...@gmail.com (Travis Bemann)
Injection-Date: Fri, 07 Apr 2023 16:38:06 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2868
 by: Travis Bemann - Fri, 7 Apr 2023 16:38 UTC

On Friday, April 7, 2023 at 8:08:15 AM UTC-5, minforth wrote:
> Anton Ertl schrieb am Freitag, 7. April 2023 um 14:17:54 UTC+2:
> > minforth <minf...@arcor.de> writes:
> > >But I am still struggling with finding good applications
> > Don't struggle! If the need does not come to you on its own, you
> > don't need them.
> That zero investment so far suits me well. ;-)
>
> "Look, Ma, I have a clever solution! All I need now is a nice problem!"

The application for closures/partial application/whatever you want
to call it in Forth that I have had is if I want to associate an address
of a data structure or an ID associated with a peripheral with a handler
word (e.g. an interrupt handler) without hard-coding it within the handler
(case in point, what if you have a word for handling multiple different
peripherals, each with their own IRQ?). Before I added support for
closures/partial application/etc. what I had to do was to manually write
words that hard-code the associated data and then call the actual
handler; if I ever revisit that code I will change it to use closures/partial
application/etc.

Travis

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<217e01a5-e8b4-4aad-bb21-765eeceece54n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23171&group=comp.lang.forth#23171

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ad4:4f0f:0:b0:5e7:b6ad:3ddf with SMTP id fb15-20020ad44f0f000000b005e7b6ad3ddfmr685350qvb.8.1680888720158;
Fri, 07 Apr 2023 10:32:00 -0700 (PDT)
X-Received: by 2002:ac8:7f83:0:b0:3e6:457f:9ed1 with SMTP id
z3-20020ac87f83000000b003e6457f9ed1mr939827qtj.5.1680888720005; Fri, 07 Apr
2023 10:32:00 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 7 Apr 2023 10:31:59 -0700 (PDT)
In-Reply-To: <dbb59818-1b25-414d-87e9-a365673ac072n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f11:fd6a:10d1:8550:9b4d:a184;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f11:fd6a:10d1:8550:9b4d:a184
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me>
<95f20fc4-4135-4c8e-895e-2f7d4ff90124n@googlegroups.com> <2023Apr7.141532@mips.complang.tuwien.ac.at>
<2f4509f4-db29-410b-88c1-77027af76a04n@googlegroups.com> <dbb59818-1b25-414d-87e9-a365673ac072n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <217e01a5-e8b4-4aad-bb21-765eeceece54n@googlegroups.com>
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
From: minfo...@arcor.de (minforth)
Injection-Date: Fri, 07 Apr 2023 17:32:00 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3520
 by: minforth - Fri, 7 Apr 2023 17:31 UTC

Travis Bemann schrieb am Freitag, 7. April 2023 um 18:38:07 UTC+2:
> On Friday, April 7, 2023 at 8:08:15 AM UTC-5, minforth wrote:
> > Anton Ertl schrieb am Freitag, 7. April 2023 um 14:17:54 UTC+2:
> > > minforth <minf...@arcor.de> writes:
> > > >But I am still struggling with finding good applications
> > > Don't struggle! If the need does not come to you on its own, you
> > > don't need them.
> > That zero investment so far suits me well. ;-)
> >
> > "Look, Ma, I have a clever solution! All I need now is a nice problem!"
> The application for closures/partial application/whatever you want
> to call it in Forth that I have had is if I want to associate an address
> of a data structure or an ID associated with a peripheral with a handler
> word (e.g. an interrupt handler) without hard-coding it within the handler
> (case in point, what if you have a word for handling multiple different
> peripherals, each with their own IRQ?). Before I added support for
> closures/partial application/etc. what I had to do was to manually write
> words that hard-code the associated data and then call the actual
> handler; if I ever revisit that code I will change it to use closures/partial
> application/etc.
I think lots of applications for closures comprise some capturing of context
(data) and using that captured context later. Starting and stopping a task in
"my" world for example. Things one could also achieve with OO methods.

Although using closure xt's (aka anonymous functions) can make you code
rather concise. But can make it also read-only, unless there is a commonly
understood syntax.

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<25da11e9-316d-4a02-9de8-6eb3c9426f44n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23172&group=comp.lang.forth#23172

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:622a:211:b0:3d7:9d03:75ae with SMTP id b17-20020a05622a021100b003d79d0375aemr1140236qtx.10.1680896296461;
Fri, 07 Apr 2023 12:38:16 -0700 (PDT)
X-Received: by 2002:a05:620a:c46:b0:743:6092:91b4 with SMTP id
u6-20020a05620a0c4600b00743609291b4mr809416qki.14.1680896296211; Fri, 07 Apr
2023 12:38:16 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 7 Apr 2023 12:38:15 -0700 (PDT)
In-Reply-To: <217e01a5-e8b4-4aad-bb21-765eeceece54n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=165.156.39.57; posting-account=Crnq4woAAABK99A43gBY5KlP3EUyAJAK
NNTP-Posting-Host: 165.156.39.57
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me>
<95f20fc4-4135-4c8e-895e-2f7d4ff90124n@googlegroups.com> <2023Apr7.141532@mips.complang.tuwien.ac.at>
<2f4509f4-db29-410b-88c1-77027af76a04n@googlegroups.com> <dbb59818-1b25-414d-87e9-a365673ac072n@googlegroups.com>
<217e01a5-e8b4-4aad-bb21-765eeceece54n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <25da11e9-316d-4a02-9de8-6eb3c9426f44n@googlegroups.com>
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
From: tabem...@gmail.com (Travis Bemann)
Injection-Date: Fri, 07 Apr 2023 19:38:16 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4996
 by: Travis Bemann - Fri, 7 Apr 2023 19:38 UTC

On Friday, April 7, 2023 at 12:32:01 PM UTC-5, minforth wrote:
> Travis Bemann schrieb am Freitag, 7. April 2023 um 18:38:07 UTC+2:
> > On Friday, April 7, 2023 at 8:08:15 AM UTC-5, minforth wrote:
> > > Anton Ertl schrieb am Freitag, 7. April 2023 um 14:17:54 UTC+2:
> > > > minforth <minf...@arcor.de> writes:
> > > > >But I am still struggling with finding good applications
> > > > Don't struggle! If the need does not come to you on its own, you
> > > > don't need them.
> > > That zero investment so far suits me well. ;-)
> > >
> > > "Look, Ma, I have a clever solution! All I need now is a nice problem!"
> > The application for closures/partial application/whatever you want
> > to call it in Forth that I have had is if I want to associate an address
> > of a data structure or an ID associated with a peripheral with a handler
> > word (e.g. an interrupt handler) without hard-coding it within the handler
> > (case in point, what if you have a word for handling multiple different
> > peripherals, each with their own IRQ?). Before I added support for
> > closures/partial application/etc. what I had to do was to manually write
> > words that hard-code the associated data and then call the actual
> > handler; if I ever revisit that code I will change it to use closures/partial
> > application/etc.
> I think lots of applications for closures comprise some capturing of context
> (data) and using that captured context later. Starting and stopping a task in
> "my" world for example. Things one could also achieve with OO methods.
>
> Although using closure xt's (aka anonymous functions) can make you code
> rather concise. But can make it also read-only, unless there is a commonly
> understood syntax.

The unfortunate thing about using closures/partial application in zeptoforth
is that it can be rather cumbersome. For starters, you have to allot/allocate
storage for them which will remain available when they are actually called.

In the case of downwards funargs the most expedient approach is to use
WITH-ALIGNED-ALLOT at the moment. However, now that I think of it,
because this is a common use-case, I could create the following words:

WITH-CLOSURE ( x bound-xt passed-xt -- )
WITH-2CLOSURE ( d bound-xt passed-xt -- )
WITH-NCLOSURE ( xn ... x0 count bound-xt passed-xt -- )

where a closure is created temporarily in the dictionary which passes
x, d, or xn ... x0 on the data stack and then calls bound-xt when called and
is placed on the data stack and is valid for the scope of passed-xt, which
is then called. These would be more convenient than the current way of
doing things.

In the case of upwards funargs other approaches would be necessary, which
would be more inconvenient. The main approach would be to plan out all the
upwards funargs one would need, and pre-allot/allocate space for them;
e.g. if one had a closure which bound the address to a data structure, a
convenient place to put the closure would be in the data structure itself.

Travis

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<9280e1ab-39d8-4943-81ba-9cb21ce586ean@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23173&group=comp.lang.forth#23173

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:4610:b0:746:bd8a:37ff with SMTP id br16-20020a05620a461000b00746bd8a37ffmr41870qkb.9.1680899972849;
Fri, 07 Apr 2023 13:39:32 -0700 (PDT)
X-Received: by 2002:a05:622a:1452:b0:3e6:3632:1304 with SMTP id
v18-20020a05622a145200b003e636321304mr1163771qtx.9.1680899972695; Fri, 07 Apr
2023 13:39:32 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 7 Apr 2023 13:39:32 -0700 (PDT)
In-Reply-To: <25da11e9-316d-4a02-9de8-6eb3c9426f44n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=79.224.98.90; posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 79.224.98.90
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me>
<95f20fc4-4135-4c8e-895e-2f7d4ff90124n@googlegroups.com> <2023Apr7.141532@mips.complang.tuwien.ac.at>
<2f4509f4-db29-410b-88c1-77027af76a04n@googlegroups.com> <dbb59818-1b25-414d-87e9-a365673ac072n@googlegroups.com>
<217e01a5-e8b4-4aad-bb21-765eeceece54n@googlegroups.com> <25da11e9-316d-4a02-9de8-6eb3c9426f44n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9280e1ab-39d8-4943-81ba-9cb21ce586ean@googlegroups.com>
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
From: minfo...@arcor.de (minforth)
Injection-Date: Fri, 07 Apr 2023 20:39:32 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2347
 by: minforth - Fri, 7 Apr 2023 20:39 UTC

Travis Bemann schrieb am Freitag, 7. April 2023 um 21:38:17 UTC+2:
> The unfortunate thing about using closures/partial application in zeptoforth
> is that it can be rather cumbersome. For starters, you have to allot/allocate
> storage for them which will remain available when they are actually called.

IOW a closure is a data instance of upvalues with an anonymous function.
If you don't want garbage collection, you could hide a destructor within the
function. But then, why not use OO in the first place?

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<7d4c984f-e12c-4e65-a122-0a34f2b8f1afn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23174&group=comp.lang.forth#23174

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:5c85:0:b0:3e6:3806:70e3 with SMTP id r5-20020ac85c85000000b003e6380670e3mr55498qta.8.1680904351539;
Fri, 07 Apr 2023 14:52:31 -0700 (PDT)
X-Received: by 2002:a05:620a:25d3:b0:74a:18e:3a6c with SMTP id
y19-20020a05620a25d300b0074a018e3a6cmr1017502qko.0.1680904351309; Fri, 07 Apr
2023 14:52:31 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 7 Apr 2023 14:52:31 -0700 (PDT)
In-Reply-To: <9280e1ab-39d8-4943-81ba-9cb21ce586ean@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=165.156.39.57; posting-account=Crnq4woAAABK99A43gBY5KlP3EUyAJAK
NNTP-Posting-Host: 165.156.39.57
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me>
<95f20fc4-4135-4c8e-895e-2f7d4ff90124n@googlegroups.com> <2023Apr7.141532@mips.complang.tuwien.ac.at>
<2f4509f4-db29-410b-88c1-77027af76a04n@googlegroups.com> <dbb59818-1b25-414d-87e9-a365673ac072n@googlegroups.com>
<217e01a5-e8b4-4aad-bb21-765eeceece54n@googlegroups.com> <25da11e9-316d-4a02-9de8-6eb3c9426f44n@googlegroups.com>
<9280e1ab-39d8-4943-81ba-9cb21ce586ean@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7d4c984f-e12c-4e65-a122-0a34f2b8f1afn@googlegroups.com>
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
From: tabem...@gmail.com (Travis Bemann)
Injection-Date: Fri, 07 Apr 2023 21:52:31 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3713
 by: Travis Bemann - Fri, 7 Apr 2023 21:52 UTC

On Friday, April 7, 2023 at 3:39:35 PM UTC-5, minforth wrote:
> Travis Bemann schrieb am Freitag, 7. April 2023 um 21:38:17 UTC+2:
> > The unfortunate thing about using closures/partial application in zeptoforth
> > is that it can be rather cumbersome. For starters, you have to allot/allocate
> > storage for them which will remain available when they are actually called.
> IOW a closure is a data instance of upvalues with an anonymous function.
> If you don't want garbage collection, you could hide a destructor within the
> function. But then, why not use OO in the first place?

With OO (which zeptoforth supports) the obvious approach is to make the
closure a member in the object which it passes to the handler itself, so it has
the same lifetime as said object itself. Even if one is not using the OO layer
per se, the same goes for storing a closure in a structure which it itself binds.
This is less flexible, however, than the garbage-collected closure approach
that is perennial in the functional programming world, which uses closures
far more pervasively. Garbage collection, though, is not an option in
zeptoforth as it is designed for embedded control; while zeptoforth does
have support for heaps, even heaps are completely optional, having to be
deliberately constructed by the user (and also there is no "the heap" - heaps
are just another data structure, so the user can be more than one of them),
the only heap that is supported "out of the box" is a small one used for
storing history for the line editor. Yes, the likes of MicroPython and eLua
use garbage-collected heaps, these hurt their real-time characteristics,
and make them unsuitable for actual real-time operation.

Travis

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<dae58634-ed05-4dd5-a711-d78339c10437n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23175&group=comp.lang.forth#23175

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:5c15:0:b0:3d6:2cd9:74e6 with SMTP id i21-20020ac85c15000000b003d62cd974e6mr1263653qti.9.1680905781966;
Fri, 07 Apr 2023 15:16:21 -0700 (PDT)
X-Received: by 2002:a05:620a:400a:b0:74a:5986:9f18 with SMTP id
h10-20020a05620a400a00b0074a59869f18mr1021928qko.3.1680905781745; Fri, 07 Apr
2023 15:16:21 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 7 Apr 2023 15:16:21 -0700 (PDT)
In-Reply-To: <7d4c984f-e12c-4e65-a122-0a34f2b8f1afn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=165.156.39.57; posting-account=Crnq4woAAABK99A43gBY5KlP3EUyAJAK
NNTP-Posting-Host: 165.156.39.57
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me>
<95f20fc4-4135-4c8e-895e-2f7d4ff90124n@googlegroups.com> <2023Apr7.141532@mips.complang.tuwien.ac.at>
<2f4509f4-db29-410b-88c1-77027af76a04n@googlegroups.com> <dbb59818-1b25-414d-87e9-a365673ac072n@googlegroups.com>
<217e01a5-e8b4-4aad-bb21-765eeceece54n@googlegroups.com> <25da11e9-316d-4a02-9de8-6eb3c9426f44n@googlegroups.com>
<9280e1ab-39d8-4943-81ba-9cb21ce586ean@googlegroups.com> <7d4c984f-e12c-4e65-a122-0a34f2b8f1afn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <dae58634-ed05-4dd5-a711-d78339c10437n@googlegroups.com>
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
From: tabem...@gmail.com (Travis Bemann)
Injection-Date: Fri, 07 Apr 2023 22:16:21 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4143
 by: Travis Bemann - Fri, 7 Apr 2023 22:16 UTC

On Friday, April 7, 2023 at 4:52:32 PM UTC-5, Travis Bemann wrote:
> On Friday, April 7, 2023 at 3:39:35 PM UTC-5, minforth wrote:
> > Travis Bemann schrieb am Freitag, 7. April 2023 um 21:38:17 UTC+2:
> > > The unfortunate thing about using closures/partial application in zeptoforth
> > > is that it can be rather cumbersome. For starters, you have to allot/allocate
> > > storage for them which will remain available when they are actually called.
> > IOW a closure is a data instance of upvalues with an anonymous function..
> > If you don't want garbage collection, you could hide a destructor within the
> > function. But then, why not use OO in the first place?
> With OO (which zeptoforth supports) the obvious approach is to make the
> closure a member in the object which it passes to the handler itself, so it has
> the same lifetime as said object itself. Even if one is not using the OO layer
> per se, the same goes for storing a closure in a structure which it itself binds.
> This is less flexible, however, than the garbage-collected closure approach
> that is perennial in the functional programming world, which uses closures
> far more pervasively. Garbage collection, though, is not an option in
> zeptoforth as it is designed for embedded control; while zeptoforth does
> have support for heaps, even heaps are completely optional, having to be
> deliberately constructed by the user (and also there is no "the heap" - heaps
> are just another data structure, so the user can be more than one of them),
> the only heap that is supported "out of the box" is a small one used for
> storing history for the line editor. Yes, the likes of MicroPython and eLua
> use garbage-collected heaps, these hurt their real-time characteristics,
> and make them unsuitable for actual real-time operation.

Correction - the user can "have" more than one heap, not "be" more than one
heap. Also, there should be a "but" before "these hurt their real-time
characteristics".

Travis

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<22e83c32-5400-4a13-886d-7b963153826en@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23177&group=comp.lang.forth#23177

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ad4:5a05:0:b0:56e:c24b:58c6 with SMTP id ei5-20020ad45a05000000b0056ec24b58c6mr904541qvb.8.1680944522479;
Sat, 08 Apr 2023 02:02:02 -0700 (PDT)
X-Received: by 2002:ad4:4a68:0:b0:5e5:bbc1:c2ed with SMTP id
cn8-20020ad44a68000000b005e5bbc1c2edmr332933qvb.4.1680944522270; Sat, 08 Apr
2023 02:02:02 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!nntp.club.cc.cmu.edu!45.76.7.193.MISMATCH!3.us.feeder.erje.net!1.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 8 Apr 2023 02:02:02 -0700 (PDT)
In-Reply-To: <7d4c984f-e12c-4e65-a122-0a34f2b8f1afn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f11:fd6a:d5a2:c280:df0f:72a3;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f11:fd6a:d5a2:c280:df0f:72a3
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me>
<95f20fc4-4135-4c8e-895e-2f7d4ff90124n@googlegroups.com> <2023Apr7.141532@mips.complang.tuwien.ac.at>
<2f4509f4-db29-410b-88c1-77027af76a04n@googlegroups.com> <dbb59818-1b25-414d-87e9-a365673ac072n@googlegroups.com>
<217e01a5-e8b4-4aad-bb21-765eeceece54n@googlegroups.com> <25da11e9-316d-4a02-9de8-6eb3c9426f44n@googlegroups.com>
<9280e1ab-39d8-4943-81ba-9cb21ce586ean@googlegroups.com> <7d4c984f-e12c-4e65-a122-0a34f2b8f1afn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <22e83c32-5400-4a13-886d-7b963153826en@googlegroups.com>
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
From: minfo...@arcor.de (minforth)
Injection-Date: Sat, 08 Apr 2023 09:02:02 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2386
 by: minforth - Sat, 8 Apr 2023 09:02 UTC

Travis Bemann schrieb am Freitag, 7. April 2023 um 23:52:32 UTC+2:
> ... the likes of MicroPython and eLua
> use garbage-collected heaps, these hurt their real-time characteristics,
> and make them unsuitable for actual real-time operation.

muPython is rather flexible there:

https://docs.micropython.org/en/latest/library/gc.html

but it wouldn't be my choice either on slow hardware.

Partial application and curry (was: locals and pure-stack closures)

<u0rpt2$1999l$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23179&group=comp.lang.forth#23179

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: ruvim.pi...@gmail.com (Ruvim)
Newsgroups: comp.lang.forth
Subject: Partial application and curry (was: locals and pure-stack closures)
Date: Sat, 8 Apr 2023 13:23:45 +0000
Organization: A noiseless patient Spider
Lines: 107
Message-ID: <u0rpt2$1999l$1@dont-email.me>
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<2023Apr3.182858@mips.complang.tuwien.ac.at>
<d0882d36-b642-4c71-808a-67c2a7b36225n@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com>
<7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me>
<129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <2023Apr7.132039@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 8 Apr 2023 13:23:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="870f79090b848e9efef2e8c812264c08";
logging-data="1353013"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187Wo4Eh2Ynjacrf7G+2DGh"
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101
Firefox/102.0
Cancel-Lock: sha1:bZBGY6qDXMnyUuqR/nXCXwbv3QY=
Content-Language: en-US
In-Reply-To: <2023Apr7.132039@mips.complang.tuwien.ac.at>
 by: Ruvim - Sat, 8 Apr 2023 13:23 UTC

On 2023-04-07 11:20, Anton Ertl wrote:
> Ruvim <ruvim.pinka@gmail.com> writes:
[...]
>> As I already mentioned [1], this idea is actually the
>> conception of partial application, which is completely independent of
>> local variables.
>
> Or of currying; from the caller's perspective the difference is small
> <https://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application>.

This difference depends on the language. E.g., in Haskell it's small,
since "f(a,b,c)" is equivalent to "f(a)(b)(c)".

In Forth the difference is significant.

Partial application itself fixes n parameters *at once* for a function.
But currying produces a function that fixes n parameters in n *steps*.

The process of implementing them brings better understanding.

Let the word "pa1" partially applies xt to one parameter x. It can be
defined as:

: pa1 ( 1*x xt -- xt ) 2>r :noname r> r> lit, compile, postpone ; ;

Then "pa2", "pa3", "pa4" can be defined as follows:

: pa2 ( 2*x xt -- xt ) pa1 pa1 ;
: pa3 ( 3*x xt -- xt ) pa2 pa1 ;
: pa4 ( 4*x xt -- xt ) pa3 pa1 ;

NB: identical data type identifiers (without indices) in a stack diagram
don't mean identical parameters.

Test cases:

: noop ; : 'noop ['] noop ;
: se ( i*x xt x -- j*x ) swap execute ;

t{ 1 'noop pa1 10 se -> 10 1 }t
t{ 2 1 'noop pa2 10 se -> 10 2 1 }t
t{ 3 2 1 'noop pa3 10 se -> 10 3 2 1 }t

The number 10 is placed on the stack just to test that the parameters
are correctly taken from the stack.

Curry (for particular number of fixed parameters) can be defined via
partial application as follows:

: cu0 ( xt -- xt ) ;
: cu1 ( xt -- xt ) ['] pa1 pa1 cu0 ;
: cu2 ( xt -- xt ) ['] pa2 pa1 cu1 ;
: cu3 ( xt -- xt ) ['] pa3 pa1 cu2 ;
: cu4 ( xt -- xt ) ['] pa4 pa1 cu3 ;

Each of this word cu{n} produces a definition that fixes n parameters in
n steps.
Test cases:

t{ 'noop cu1 1 se 10 se -> 10 1 }t
t{ 'noop cu2 1 se 2 se 10 se -> 10 2 1 }t
t{ 'noop cu3 1 se 2 se 3 se 10 se -> 10 3 2 1 }t

NB: we apply "execute" n times to fix n parameters.

A definition of a word "ncu ( xt u.n -- xt )" that produces xt that
fixes arbitrary n parameters in n steps — is a puzzle for the reader (I
already posted a solution with its proof in 2018).

Partial application can be also defined via curry as follows:

synonym e execute

: pa1 ( 1*x xt -- xt ) cu1 e ;
: pa2 ( 2*x xt -- xt ) cu2 e e ;
: pa3 ( 3*x xt -- xt ) cu3 e e e ;
: pa4 ( 4*x xt -- xt ) cu4 e e e e ;

From the information theory point of view, partial application is a
reduction, since the produced function "contains" less information than
the original one. But currying is a lossless transformation — the
produced function "contains" as much information as the original one.

> Plus, I had not known the term before, although it sounded familiar:
> <https://en.wikipedia.org/wiki/Partial_application> starts by saying:
>
> |Not to be confused with partial evaluation
>
> and so I found out that I was thinking about "partial evaluation" when
> you wrote "partial application".

Oh, I see. Moreover, partial evaluation is a specific case of partial
application, I think. And partial application can contain partial
evaluation under the hood, but it's not necessary.

[...]

--
Ruvim

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<u0rvvl$1a5bf$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23181&group=comp.lang.forth#23181

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: ruvim.pi...@gmail.com (Ruvim)
Newsgroups: comp.lang.forth
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
Date: Sat, 8 Apr 2023 15:07:32 +0000
Organization: A noiseless patient Spider
Lines: 110
Message-ID: <u0rvvl$1a5bf$1@dont-email.me>
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<2023Apr3.182858@mips.complang.tuwien.ac.at>
<d0882d36-b642-4c71-808a-67c2a7b36225n@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com>
<7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me>
<129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <2023Apr7.132039@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 8 Apr 2023 15:07:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="870f79090b848e9efef2e8c812264c08";
logging-data="1381743"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9ubsZDlToem5fnRNTU1ae"
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101
Firefox/102.0
Cancel-Lock: sha1:krhiMwqOocNVKC3CA+gdBPXOK9s=
Content-Language: en-US
In-Reply-To: <2023Apr7.132039@mips.complang.tuwien.ac.at>
 by: Ruvim - Sat, 8 Apr 2023 15:07 UTC

On 2023-04-07 11:20, Anton Ertl wrote:
> Ruvim <ruvim.pinka@gmail.com> writes:
>> On 2023-04-05 07:33, Anton Ertl wrote:
>>> We would have missed this idea if we had rejected everything
>>> to do with locals from the start.
>>
>> I cannot agree.
>
> You were not involved.

Yes, sorry I wasn't.

Well, I awkwardly expressed my thought. I wanted to say, you probably
would eventually come to this idea as the conception of partial
application anyway (independently of local variables).

[...]

>> — A closure (a lexical closure) is created by binding *named* objects
>>from the lexical environment.
>
> In Forth we do not have a lexical environment.

Sure, we have. Formally, it depends on particular definition of
"lexical environment" term.

Intuitively, lexical environment is a set of information that is used to
recognize lexemes (or, on which recognizing of lexemes depends on).

> So we use the term
> "closure" to refer to the thing that is used for the purposes that
> closures are used for in languages that have a lexical environment.
> You may prefer to call it a "partially-applied colon definition", but
> "closure" has the advantage of being much shorter.

"colon definition" is an informal notion.

Formally, we have "Forth definition" (not necessary a colon definition,
and even not necessary a named definition), that is often abbreviated to
just "definition", when it's clear from the context that we talk about a
Forth definition.

BTW, the notion of "anonymous definition" in Forth and "anonymous
function" in other programming languages mean the same, I think. Then,
*ordinary* named definitions in Forth and named functions in other
languages also mean the same.

Therefore, it's pretty clear what "partially applied function" means in
the context of Forth.

Concerning "execution" — it corresponds better not to "function
application", but to "function evaluation" (in mathematical sense). Then
I was wrong in my previous message that "partial evaluation is a
specific case of partial application".

Well, if we call a partially applied definition "closure", how we will
call a real closure (which binds lexical environment including local
variables)?

>> So a problem is how to create a partially applied function dynamically,
>> and how to free resources of an already unneeded function
>
> It's pretty straightforward using "carnal knowledge", and as you
> demonstrate, pretty messy if you want to use currently standard means;
> so I think the better question is: What is missing from standard
> Forth?

> Is there something that is currently "carnal knowledge", but
> should be standardized, or should we standardize nothing at a lower
> level, and intead standardize the partial application word. (Probably
> at the present time the answer is that there is not enough common
> practice to standardize anything, but let's assume that at some point
> this will change.)

I think, we need them all — some things on a lower level and some things
on a higher level.

For example, there is a general need for dynamic compilation, execution
of the resulting definitions, and then freeing them (freeing the
resources that were taken doing compilation).

And such means can be used to implement partial application too.

In the same time we can consider words like:

1apply ( x xt -- xt )
napply ( i*x u.i xt -- xt )
1fapply ( xt -- xt ) ( F: r -- )
nfapply ( u.i xt -- xt ) ( F: i*r -- )
free-definition ( xt -- )
\ it may throw an exception if xt
\ is not from the "apply" family words
\ or was already freed.

--
Ruvim

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<u0s143$1a9r7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23182&group=comp.lang.forth#23182

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: ruvim.pi...@gmail.com (Ruvim)
Newsgroups: comp.lang.forth
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
Date: Sat, 8 Apr 2023 15:26:59 +0000
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <u0s143$1a9r7$1@dont-email.me>
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<2023Apr3.182858@mips.complang.tuwien.ac.at>
<d0882d36-b642-4c71-808a-67c2a7b36225n@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com>
<7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me>
<129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <2023Apr7.132039@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 8 Apr 2023 15:26:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="870f79090b848e9efef2e8c812264c08";
logging-data="1386343"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Mm7M3H/6rhu/ERaAz0ez7"
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101
Firefox/102.0
Cancel-Lock: sha1:pVMgh7uTtK8GQgQxzspnzb6B1z4=
Content-Language: en-US
In-Reply-To: <2023Apr7.132039@mips.complang.tuwien.ac.at>
 by: Ruvim - Sat, 8 Apr 2023 15:26 UTC

On 2023-04-07 11:20, Anton Ertl wrote:
[...]

> So we use the term
> "closure" to refer to the thing that is used for the purposes that
> closures are used for in languages that have a lexical environment.

In general, it's a bad argument.

If different tools are used for the same purpose, it doesn't mean that
each of this tools should be called by the same name, just because they
all occasionally are used for the same purpose.

--
Ruvim

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<a9d9d273-7ded-4af2-b009-05fed8bcd40bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23200&group=comp.lang.forth#23200

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:1a1e:b0:742:4d08:a8bd with SMTP id bk30-20020a05620a1a1e00b007424d08a8bdmr2417899qkb.4.1681029721162;
Sun, 09 Apr 2023 01:42:01 -0700 (PDT)
X-Received: by 2002:ad4:59d1:0:b0:56f:795:82cd with SMTP id
el17-20020ad459d1000000b0056f079582cdmr1531970qvb.10.1681029720915; Sun, 09
Apr 2023 01:42:00 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!nntp.club.cc.cmu.edu!45.76.7.193.MISMATCH!3.us.feeder.erje.net!1.us.feeder.erje.net!feeder.erje.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sun, 9 Apr 2023 01:42:00 -0700 (PDT)
In-Reply-To: <u0rvvl$1a5bf$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f11:fdd3:858b:51b8:f82e:59e3;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f11:fdd3:858b:51b8:f82e:59e3
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<2023Apr3.182858@mips.complang.tuwien.ac.at> <d0882d36-b642-4c71-808a-67c2a7b36225n@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <2023Apr7.132039@mips.complang.tuwien.ac.at> <u0rvvl$1a5bf$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a9d9d273-7ded-4af2-b009-05fed8bcd40bn@googlegroups.com>
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
From: minfo...@arcor.de (minforth)
Injection-Date: Sun, 09 Apr 2023 08:42:01 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 14
 by: minforth - Sun, 9 Apr 2023 08:42 UTC

Ruvim schrieb am Samstag, 8. April 2023 um 17:07:36 UTC+2:
> On 2023-04-07 11:20, Anton Ertl wrote:

> > In Forth we do not have a lexical environment.
> Sure, we have. Formally, it depends on particular definition of
> "lexical environment" term.
>
> Intuitively, lexical environment is a set of information that is used to
> recognize lexemes (or, on which recognizing of lexemes depends on).

I use a header cell containing the FNV1a hash-value of the word's/local's name.
This accelerates recognizing/searching for words/locals significantly.

Target overlays/binaries do not contain plain-text names but the hash values.
With this information "lexemes" can be recognized nevertheless.

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<u113fb$26m7c$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23213&group=comp.lang.forth#23213

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: ruvim.pi...@gmail.com (Ruvim)
Newsgroups: comp.lang.forth
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
Date: Mon, 10 Apr 2023 13:37:47 +0000
Organization: A noiseless patient Spider
Lines: 92
Message-ID: <u113fb$26m7c$1@dont-email.me>
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<2023Apr3.182858@mips.complang.tuwien.ac.at>
<d0882d36-b642-4c71-808a-67c2a7b36225n@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com>
<7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me>
<129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me>
<2023Apr7.135118@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 10 Apr 2023 13:37:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b4f777306a2d1e98841be177c967f5b7";
logging-data="2316524"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198dWwE6SsxPn1bSmKsek7L"
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101
Firefox/102.0
Cancel-Lock: sha1:v8zeGAC9ReWVp3iN58sRf6gbmTc=
In-Reply-To: <2023Apr7.135118@mips.complang.tuwien.ac.at>
Content-Language: en-US
 by: Ruvim - Mon, 10 Apr 2023 13:37 UTC

On 2023-04-07 11:51, Anton Ertl wrote:
[...]

>> Without local variables in general, or without *ability* to bind the
>> outer local variables, closures are trivial. I'm not sure it's still
>> correct to call such functions "closures". Therefor, in Factor, Joy,
>> Cat, Forth, such functions are intentionally called "quotations".
>>
>> If we don't call quotations "closures", then we rather shouldn't call
>> partially applied functions "closures" too.
>
> That does not follow. Quotations neither are closures nor do they
> serve the purpose of closures.

Yes. But sometimes they can be used to solve a problem for which
closures are also used.

> What Gforth calls closures is intended
> to be used for the purpose that closures (as well as curried and
> partially-applied functions) are used for in Scheme; and if we have
>
> [n:d + ;]
>
> (what I call a pure-stack closure), it's not a partially-applied (or
> partially-EXECUTEd?) colon definition, because no partial
> application/execution has happened, and it's not a colon definition.

Partial application happens when a new xt is returned by this construct.

The construct

[n:d + ;]

is actually a sugar over

[: + ;] partial1

Where "partial1 ( x1 xt1 -- xt )" performs partial application.

> It might be called a curried quotation if you are unhappy with
> "closure", but I am happy with "closure" (but a also call the
> resulting xt the xt of a closure, so I am quite loose in terminology
> here.
>
>> Also, if the outer local variables are not bound in a function, it's
>> probably confusing if this function would be called "closure".
>
> About as confusing as calling a colon definition a "function".
>
>> Well, if we still want to call partially applied functions "closures",
>> they shouldn't be "lexical closures", but some other kind of closures.
>
> "Flat closure" or "Gforth closure" is fine with me.
>
>> And "pure-stack closures" is not well suited either, I think.
>
> "Pure-stack" contrasts with the closures that have locals on the
> inside:
>
> pure-stack closure: [n:d + ;]
> other Gforth closure: [{: n :}d n + ;]

Closures that are created in the same lexical environment, share the
same external variables (their state).

For example, see in JavaScript:

x = (function (){
var a ; a = 0;
return [ ()=>{ a+=1; return a}, ()=>{ a+=10; return a} ]
})();

x[0]() // "1"
x[1]() // "11"
x[0]() // "12"
x[0]() // "13"
x[1]() // "23"

Gforth "closures" does not provide this functionality. Because actually
they are partially applied functions (partially applied definitions, if
you like), which are defined in special syntax.

--
Ruvim

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<17b4b209-f872-446e-ad2b-854236a982dbn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23218&group=comp.lang.forth#23218

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:1844:b0:570:ed88:8a13 with SMTP id d4-20020a056214184400b00570ed888a13mr1913812qvy.6.1681188959285;
Mon, 10 Apr 2023 21:55:59 -0700 (PDT)
X-Received: by 2002:a05:622a:307:b0:3e6:720f:bada with SMTP id
q7-20020a05622a030700b003e6720fbadamr4877831qtw.2.1681188959112; Mon, 10 Apr
2023 21:55:59 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 10 Apr 2023 21:55:58 -0700 (PDT)
In-Reply-To: <u113fb$26m7c$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f11:fd62:8d8f:2c22:6138:540f;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f11:fd62:8d8f:2c22:6138:540f
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<2023Apr3.182858@mips.complang.tuwien.ac.at> <d0882d36-b642-4c71-808a-67c2a7b36225n@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me>
<2023Apr7.135118@mips.complang.tuwien.ac.at> <u113fb$26m7c$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <17b4b209-f872-446e-ad2b-854236a982dbn@googlegroups.com>
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
From: minfo...@arcor.de (minforth)
Injection-Date: Tue, 11 Apr 2023 04:55:59 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2621
 by: minforth - Tue, 11 Apr 2023 04:55 UTC

Ruvim schrieb am Montag, 10. April 2023 um 15:37:50 UTC+2:
> Closures that are created in the same lexical environment, share the
> same external variables (their state).
>
> For example, see in JavaScript:
>
> x = (function (){
> var a ; a = 0;
> return [ ()=>{ a+=1; return a}, ()=>{ a+=10; return a} ]
> })();
>
> x[0]() // "1"
> x[1]() // "11"
> x[0]() // "12"
> x[0]() // "13"
> x[1]() // "23"
>
>
> Gforth "closures" does not provide this functionality. Because actually
> they are partially applied functions (partially applied definitions, if
> you like), which are defined in special syntax.

"Sharing" external free variables, or getting an independent copy of them
(the lexical environment) at time of closure creation means a huge difference.
Each somewhat functional language seems to have cooked its own recipe
for closures, and IMO Javascript has overdone it here.

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<2023Apr11.085403@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23219&group=comp.lang.forth#23219

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
Date: Tue, 11 Apr 2023 06:54:03 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 99
Message-ID: <2023Apr11.085403@mips.complang.tuwien.ac.at>
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com> <c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com> <u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com> <u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at> <u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me> <2023Apr7.135118@mips.complang.tuwien.ac.at> <u113fb$26m7c$1@dont-email.me>
Injection-Info: dont-email.me; posting-host="70ef2cc73bce7fdeacc600929183d881";
logging-data="2738194"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18p82yPYB/pkfqv2Y9RPzrL"
Cancel-Lock: sha1:9epGFsfME7kyl3LQCEJJHt9OZw8=
X-newsreader: xrn 10.11
 by: Anton Ertl - Tue, 11 Apr 2023 06:54 UTC

Ruvim <ruvim.pinka@gmail.com> writes:
>On 2023-04-07 11:51, Anton Ertl wrote:
>> What Gforth calls closures is intended
>> to be used for the purpose that closures (as well as curried and
>> partially-applied functions) are used for in Scheme; and if we have
>>
>> [n:d + ;]
>>
>> (what I call a pure-stack closure), it's not a partially-applied (or
>> partially-EXECUTEd?) colon definition, because no partial
>> application/execution has happened, and it's not a colon definition.
>
>Partial application happens when a new xt is returned by this construct.

Yes. So the construct itself can be called a curried definition, or a
definition with two-stage parameter passing.

>The construct
>
> [n:d + ;]
>
>is actually a sugar over
>
> [: + ;] partial1
>
>Where "partial1 ( x1 xt1 -- xt )" performs partial application.

Except that we don't have PARTIAL1.

>Closures that are created in the same lexical environment, share the
>same external variables (their state).
>
>For example, see in JavaScript:
>
>x = (function (){
> var a ; a = 0;
> return [ ()=>{ a+=1; return a}, ()=>{ a+=10; return a} ]
>})();
>
>x[0]() // "1"
>x[1]() // "11"
>x[0]() // "12"
>x[0]() // "13"
>x[1]() // "23"

>Gforth "closures" does not provide this functionality.

[: ( -- addr )
align here >r 0 ,
here
r@ [n:h 1 over +! @ ;] ,
r> [n:h 10 over +! @ ;] ,
;] execute constant x

x @ execute . \ 1
x cell+ @ execute . \ 11
x @ execute . \ 12
x @ execute . \ 13
x cell+ @ execute . \ 23

Here I used assignment conversion, which has been described by Dybvig
in the Scheme literature in 1987. Each invocation of the quotation
produces a new instance of the variable in the dictionary with ",",
and the address of this variable is then passed to the two closures,
both of which then access the same variable. Section 5 of
<http://www.euroforth.org/ef18/papers/ertl.pdf> describes the
application of assignment conversion to Forth. The closures are
allocated on the heap here, to make the allocation of the array in the
dictionary convenient.

The code above uses only stack stuff. A highly locals-oriented
version is:

[: ( -- addr )
0 <{: w^ a :}d a ;> drop {: a :}
here
a [{: a :}h 1 a +! a @ ;] ,
a [{: a :}h 10 a +! a @ ;] ,
;] execute constant x

x @ execute .
x cell+ @ execute .
x @ execute .
x @ execute .
x cell+ @ execute .

Here the <{: ... ;> syntax is used for producing home locations for
variables that you need to share, because they are changed. It
provides a common syntax for doing this for the different allocation
methods; of coures for each allocation method you can do it with
conventional means, but the syntax for the different allocation
methods is quite different.

- 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 2022: https://euro.theforth.net

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<2023Apr11.101328@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23220&group=comp.lang.forth#23220

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
Date: Tue, 11 Apr 2023 08:13:28 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 54
Message-ID: <2023Apr11.101328@mips.complang.tuwien.ac.at>
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com> <u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com> <u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at> <u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me> <2023Apr7.135118@mips.complang.tuwien.ac.at> <u113fb$26m7c$1@dont-email.me> <17b4b209-f872-446e-ad2b-854236a982dbn@googlegroups.com>
Injection-Info: dont-email.me; posting-host="70ef2cc73bce7fdeacc600929183d881";
logging-data="2741277"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ucLdM67Qv/1fmrMsRALJG"
Cancel-Lock: sha1:sDWU6bQRsf2bKS4w+sKqobD9uMQ=
X-newsreader: xrn 10.11
 by: Anton Ertl - Tue, 11 Apr 2023 08:13 UTC

minforth <minforth@arcor.de> writes:
>Ruvim schrieb am Montag, 10. April 2023 um 15:37:50 UTC+2:
>> Closures that are created in the same lexical environment, share the
>> same external variables (their state).
>>
>> For example, see in JavaScript:
>>
>> x = (function (){
>> var a ; a = 0;
>> return [ ()=>{ a+=1; return a}, ()=>{ a+=10; return a} ]
>> })();
>>
>> x[0]() // "1"
>> x[1]() // "11"
>> x[0]() // "12"
>> x[0]() // "13"
>> x[1]() // "23"
>>
>>
>> Gforth "closures" does not provide this functionality. Because actually
>> they are partially applied functions (partially applied definitions, if
>> you like), which are defined in special syntax.
>
>"Sharing" external free variables, or getting an independent copy of them
>(the lexical environment) at time of closure creation means a huge difference.
>Each somewhat functional language seems to have cooked its own recipe
>for closures, and IMO Javascript has overdone it here.

This kind of sharing is an old concept already present in Algol 60,
exercised in the Man-or-Boy test (in the variables k and B) and in
Jensen's device; and of course you can use it in Scheme. It's not
needed in pure functional languages, because they don't change the
values of variables; so you can just replicate the value, no need to
worry about another user getting a stale value.

While (some) Scheme compilers use assignment conversion as a compiler
technique, we decided to leave this job to the programmer in order to
simplify the implementation of closures. I think that this is the
right choice:

* The need for assignment conversion rare; I think we have only used
it for proof-of-concept examples yet. So leaving it to the
programmer is not very burdensome.

* It makes the costs of things much more obvious. In the original
(Algol 60) man-or-boy program it's not obvious that k has this extra
cost, while in the Forth version it is quite easy to see.

- 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 2022: https://euro.theforth.net

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<2023Apr11.165247@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23223&group=comp.lang.forth#23223

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
Date: Tue, 11 Apr 2023 14:52:47 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 26
Message-ID: <2023Apr11.165247@mips.complang.tuwien.ac.at>
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com> <7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com> <u0fr7e$353a0$1@dont-email.me> <129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com> <u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at> <u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me> <2023Apr7.135118@mips.complang.tuwien.ac.at> <u113fb$26m7c$1@dont-email.me> <2023Apr11.085403@mips.complang.tuwien.ac.at>
Injection-Info: dont-email.me; posting-host="70ef2cc73bce7fdeacc600929183d881";
logging-data="2802086"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19gEo9EvJ5Rq3+6g7flf7UF"
Cancel-Lock: sha1:hJfOZdn+Ep+9kPTMYNv3rvMxpMY=
X-newsreader: xrn 10.11
 by: Anton Ertl - Tue, 11 Apr 2023 14:52 UTC

anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>[: ( -- addr )
> 0 <{: w^ a :}d a ;> drop {: a :}
> here
> a [{: a :}h 1 a +! a @ ;] ,
> a [{: a :}h 10 a +! a @ ;] ,
>;] execute constant x

There are 4 definitions of a local A here, each within its own scope,
but still humans may find it hard to see which use of A refers to
which definition. So I have varied this so that each local gets a
unique name:

[: ( -- addr )
0 <{: w^ a1 :}d a1 ;> drop {: a2 :}
here
a2 [{: a3 :}h 1 a3 +! a3 @ ;] ,
a2 [{: a4 :}h 10 a4 +! a4 @ ;] ,
;] execute constant x

- 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 2022: https://euro.theforth.net

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<u13o9b$2l6ve$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23224&group=comp.lang.forth#23224

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: ruvim.pi...@gmail.com (Ruvim)
Newsgroups: comp.lang.forth
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
Date: Tue, 11 Apr 2023 13:34:19 +0000
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <u13o9b$2l6ve$1@dont-email.me>
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<2023Apr3.182858@mips.complang.tuwien.ac.at>
<d0882d36-b642-4c71-808a-67c2a7b36225n@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com>
<7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me>
<129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <2023Apr7.132039@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 11 Apr 2023 13:45:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="07e60bb45d55f95539f02b83b0b06909";
logging-data="2792430"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+y+jjFCh7fr44ZWKmCKWJi"
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101
Firefox/102.0
Cancel-Lock: sha1:1L5xIEeYVkOiTj+SBX/5LXJDml4=
Content-Language: en-US
In-Reply-To: <2023Apr7.132039@mips.complang.tuwien.ac.at>
 by: Ruvim - Tue, 11 Apr 2023 13:34 UTC

On 2023-04-07 11:20, Anton Ertl wrote:
> Ruvim <ruvim.pinka@gmail.com> writes:
[...]
>> So a problem is how to create a partially applied function dynamically,
>> and how to free resources of an already unneeded function
>
> It's pretty straightforward using "carnal knowledge", and as you
> demonstrate, pretty messy if you want to use currently standard means;

I have implemented this idea as a PoC (a proof of concept prototype)
[1]. It took about 50 lines of code.

Since in Standard Forth we cannot create a new xt (new definition) in
any particular moment, and cannot remove a particular definition, I
create a pool of definitions (a pool of thunks [2]) in advance, which
can be reused many times.

This implementation is not quite efficient — I use only cons-based
dynamic lists. A more efficient way is to use a stack to store the pool
of idle items (which are available for hiring), and use a hash-table to
get the data address from a thunk xt (or use create-does and ">body",
but then I have to provide a dummy name for each definition in the pool).

The cons-based cells and lists is a very easy tool for prototyping. It's
provide simple memory management, and I even don't need to create usual
data structures.

Also, the linking between an xt and the corresponding data field is a
useful thing by itself (without connection to a named definitions).

What about a word like "bind-here ( xt1 -- xt2 )", which partially
applies xt1 to the value of the data-space pointer? An important
requirement is that ">body" should be applicable to xt2.

Test cases:

t{ ' 2@ bind-here ( xt ) 1 , 2 , execute -> 2 1 }t
t{ [: dup . @ . ;] bind-here >body here = -> true }t

It's a more basic tool than "create-does", and it allows to better
optimize the code since the bound parameter cannot be changed (unlike in
create-does).

Another thing concerning dynamic partially applied functions
(definitions) is that if you create chains of such definitions, it's
cumbersome to manually release them.

Probably some helper tool would be useful to define a kind of domain,
and release all definitions (or resources in general) that are bound to
this domain.

[1]
https://github.com/ruv/puzzle-in-forth/blob/main/extension/partial-application.fth

[2] https://en.wikipedia.org/wiki/Thunk_(functional_programming)

--
Ruvim

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<2474ea5a-9778-40fa-b634-ed8e0eb0ccd3n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23227&group=comp.lang.forth#23227

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:4a41:b0:5e6:75b9:4889 with SMTP id ph1-20020a0562144a4100b005e675b94889mr171128qvb.0.1681245616760;
Tue, 11 Apr 2023 13:40:16 -0700 (PDT)
X-Received: by 2002:a05:620a:4048:b0:74a:28c4:64ea with SMTP id
i8-20020a05620a404800b0074a28c464eamr3784879qko.6.1681245616527; Tue, 11 Apr
2023 13:40:16 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!nntp.club.cc.cmu.edu!45.76.7.193.MISMATCH!3.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 11 Apr 2023 13:40:16 -0700 (PDT)
In-Reply-To: <2023Apr11.101328@mips.complang.tuwien.ac.at>
Injection-Info: google-groups.googlegroups.com; posting-host=178.7.110.55; posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 178.7.110.55
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com> <u0fr7e$353a0$1@dont-email.me>
<129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com> <u0ijjv$3klvj$1@dont-email.me>
<2023Apr5.093335@mips.complang.tuwien.ac.at> <u0mg0e$c227$1@dont-email.me>
<u0oj86$ofbf$1@dont-email.me> <2023Apr7.135118@mips.complang.tuwien.ac.at>
<u113fb$26m7c$1@dont-email.me> <17b4b209-f872-446e-ad2b-854236a982dbn@googlegroups.com>
<2023Apr11.101328@mips.complang.tuwien.ac.at>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2474ea5a-9778-40fa-b634-ed8e0eb0ccd3n@googlegroups.com>
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
From: minfo...@arcor.de (minforth)
Injection-Date: Tue, 11 Apr 2023 20:40:16 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3808
 by: minforth - Tue, 11 Apr 2023 20:40 UTC

Anton Ertl schrieb am Dienstag, 11. April 2023 um 10:32:56 UTC+2:
> minforth <minf...@arcor.de> writes:
> >Ruvim schrieb am Montag, 10. April 2023 um 15:37:50 UTC+2:
> >> Closures that are created in the same lexical environment, share the
> >> same external variables (their state).
> >>
> >> For example, see in JavaScript:
> >>
> >> x = (function (){
> >> var a ; a = 0;
> >> return [ ()=>{ a+=1; return a}, ()=>{ a+=10; return a} ]
> >> })();
> >>
> >> x[0]() // "1"
> >> x[1]() // "11"
> >> x[0]() // "12"
> >> x[0]() // "13"
> >> x[1]() // "23"
> >>
> >>
> >> Gforth "closures" does not provide this functionality. Because actually
> >> they are partially applied functions (partially applied definitions, if
> >> you like), which are defined in special syntax.
> >
> >"Sharing" external free variables, or getting an independent copy of them
> >(the lexical environment) at time of closure creation means a huge difference.
> >Each somewhat functional language seems to have cooked its own recipe
> >for closures, and IMO Javascript has overdone it here.
> This kind of sharing is an old concept already present in Algol 60,
> exercised in the Man-or-Boy test (in the variables k and B) and in
> Jensen's device; and of course you can use it in Scheme. It's not
> needed in pure functional languages, because they don't change the
> values of variables; so you can just replicate the value, no need to
> worry about another user getting a stale value.
>
> While (some) Scheme compilers use assignment conversion as a compiler
> technique, we decided to leave this job to the programmer in order to
> simplify the implementation of closures. I think that this is the
> right choice:
>
> * The need for assignment conversion rare; I think we have only used
> it for proof-of-concept examples yet. So leaving it to the
> programmer is not very burdensome.
>
> * It makes the costs of things much more obvious. In the original
> (Algol 60) man-or-boy program it's not obvious that k has this extra
> cost, while in the Forth version it is quite easy to see.

Thanks for your explanations! Really appreciated!

Re: locals and pure-stack closures (was: GOTO and LABEL ...)

<u19af2$121do$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23233&group=comp.lang.forth#23233

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ruvim.pi...@gmail.com (Ruvim)
Newsgroups: comp.lang.forth
Subject: Re: locals and pure-stack closures (was: GOTO and LABEL ...)
Date: Thu, 13 Apr 2023 16:26:08 +0000
Organization: A noiseless patient Spider
Lines: 191
Message-ID: <u19af2$121do$2@dont-email.me>
References: <ae7ed4c5-3b82-4384-9e00-a5152281325cn@googlegroups.com>
<c71560c7-4e7a-4bbd-8a6c-a5312028ac21n@googlegroups.com>
<7a518a28-3d0d-4d25-b329-fc5cd1516a53n@googlegroups.com>
<u0fr7e$353a0$1@dont-email.me>
<129546f4-3122-4b3f-82a7-b613b8a50a2en@googlegroups.com>
<u0ijjv$3klvj$1@dont-email.me> <2023Apr5.093335@mips.complang.tuwien.ac.at>
<u0mg0e$c227$1@dont-email.me> <u0oj86$ofbf$1@dont-email.me>
<2023Apr7.135118@mips.complang.tuwien.ac.at> <u113fb$26m7c$1@dont-email.me>
<2023Apr11.085403@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 13 Apr 2023 16:26:11 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="78c38244252f0f656dad334a730f8cdf";
logging-data="1115576"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19h9RDo9gnrjc9dARVeuGrM"
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101
Firefox/102.0
Cancel-Lock: sha1:EOzd0mj01wsfloze7qZoPXLzqc0=
In-Reply-To: <2023Apr11.085403@mips.complang.tuwien.ac.at>
Content-Language: en-US
 by: Ruvim - Thu, 13 Apr 2023 16:26 UTC

(repeated message due to a problem with delivery)
On 2023-04-11 06:54, Anton Ertl wrote:
> Ruvim <ruvim.pinka@gmail.com> writes:
>> On 2023-04-07 11:51, Anton Ertl wrote:
>>> What Gforth calls closures is intended
>>> to be used for the purpose that closures (as well as curried and
>>> partially-applied functions) are used for in Scheme; and if we have
>>>
>>> [n:d + ;]
>>>
>>> (what I call a pure-stack closure), it's not a partially-applied (or
>>> partially-EXECUTEd?) colon definition, because no partial
>>> application/execution has happened, and it's not a colon definition.
>>
>> Partial application happens when a new xt is returned by this construct.
>
> Yes. So the construct itself can be called a curried definition, or a
> definition with two-stage parameter passing.

I like the variant "curried definition". My rationale: when it's
performed (i.e., at run-time), it creates a new definition using partial
application, and returns the corresponding xt — and it's similar to what
a curried function does.

The fragment:

[n:d + ;]

is equivalent to:

[: + ;] partial1

that is equivalent to:

[ [: + ;] curry1 compile, ]

that is equivalent to:

curried1(+)

where "curried1(+)" is defined as:

[: + ;] curry1 alias curried1(+)

Also, a curried function returns a partially applied function, and it
has nothing to do with lexical closures at all. And it's true for this
construct too (e.g. "[n:d + ;]").

>> The construct
>>
>> [n:d + ;]
>>
>> is actually a sugar over
>>
>> [: + ;] partial1
>>
>> Where "partial1 ( x1 xt1 -- xt )" performs partial application.
>
> Except that we don't have PARTIAL1.

Well, this construct is a sugar conceptually, and anyway, this construct
is equivalent to this code, regardless whether you have "partial1 (i.e.,
the implementation details don't matter).

>> Closures that are created in the same lexical environment, share the
>> same external variables (their state).
>>
>> For example, see in JavaScript:
>>
>> x = (function (){
>> var a ; a = 0;
>> return [ ()=>{ a+=1; return a}, ()=>{ a+=10; return a} ]
>> })();
>>
>> x[0]() // "1"
>> x[1]() // "11"
>> x[0]() // "12"
>> x[0]() // "13"
>> x[1]() // "23"
>
>> Gforth "closures" does not provide this functionality.
>
> [: ( -- addr )
> align here >r 0 ,
> here
> r@ [n:h 1 over +! @ ;] ,
> r> [n:h 10 over +! @ ;] ,
> ;] execute constant x
>
> x @ execute . \ 1
> x cell+ @ execute . \ 11
> x @ execute . \ 12
> x @ execute . \ 13
> x cell+ @ execute . \ 23

OK. My argument is not quite suitable. In your example the required
behavior is implemented without closures.

A closure is a function that *directly* (not by argument passing) refers
to identifiers defined in the environment in which the function is
defined, but not in the environment of the function call. If such a call
is not possible, the function is not a closure.

In a broad sense, even a function defined in a module is a closure over
the local identifiers of that module. In a narrow sense, a closure is a
nested function only (a function defined within another function) that
refers to identifiers defined in an enclosing function.

In the Forth terminology, a closure is an anonymous inner definition
that directly mention some names defined in some of enclosing definitions.

In your example, the inner definitions don't mention a *name* defined in
the containing definition. So, lexical closures are not involved.

> Here I used assignment conversion, which has been described by Dybvig
> in the Scheme literature in 1987.

Assignment conversion of a closure is one of possible ways to
*implement* supporting of closures in a language. Another way is
run-time code generation.

If you are forced to do closure conversion by hand, then the language
does not support closures.

> Each invocation of the quotation
> produces a new instance of the variable in the dictionary with ",",
> and the address of this variable is then passed to the two closures,
> both of which then access the same variable. Section 5 of
> <http://www.euroforth.org/ef18/papers/ertl.pdf> describes the
> application of assignment conversion to Forth.

| In most of the rest of this paper, closure
| refers to the data structure, and it’s
| Forth source code representation.

It looks like you consider only a back-end part to support closures in
Forth.

Without a front-end, — the ability to directly refer names defined in an
enclosing definition — I cannot say that closures are supported by a
language (in its syntax and semantics).

> The closures are
> allocated on the heap here, to make the allocation of the array in the
> dictionary convenient.
>
> The code above uses only stack stuff. A highly locals-oriented
> version is:
>
> [: ( -- addr )
> 0 <{: w^ a :}d a ;> drop {: a :}
> here
> a [{: a :}h 1 a +! a @ ;] ,
> a [{: a :}h 10 a +! a @ ;] ,
> ;] execute constant x

In this case too, no inner definition mentions a *name* defined in the
containing definition.

>
> x @ execute .
> x cell+ @ execute .
> x @ execute .
> x @ execute .
> x cell+ @ execute .
>
> Here the <{: ... ;> syntax is used for producing home locations for
> variables that you need to share, because they are changed. It
> provides a common syntax for doing this for the different allocation
> methods; of coures for each allocation method you can do it with
> conventional means, but the syntax for the different allocation
> methods is quite different.
>

--
Ruvim

Pages:123456
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor