Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

We can predict everything, except the future.


devel / comp.lang.lisp / Re: Closures

SubjectAuthor
* Closuresnone
+* Re: ClosuresAnton Ertl
|`* Re: Closuresnone
| `* Re: ClosuresKaz Kylheku
|  `- Re: Closuresnone
`* Re: ClosuresKaz Kylheku
 `* Re: Closuresdxforth
  `- Re: ClosuresKaz Kylheku

1
Closures

<nnd$46df7f6f$350f7542@2161f37a21843b9e>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17444&group=comp.lang.lisp#17444

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Closures
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$46df7f6f$350f7542@2161f37a21843b9e>
Organization: KPN B.V.
Date: Mon, 14 Aug 2023 10:19:55 +0200
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe006.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 43
Injection-Date: Mon, 14 Aug 2023 10:19:55 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2451
 by: none - Mon, 14 Aug 2023 08:19 UTC

I finally understood what closures mean.
In Forth parlance it is a search order that is kept with an
Forth word. Each time the Forth word is invoked, the search
order is obeyed on top of the parameters that are passed.
It puzzled me that the search order need not be restored after
calling a lisp word, but it is build in.
Restoring seemed to be a stumbling block for implementing
tail optimisation, but it is not needed.

In implementing lisp the lisp search order has to be separate
from the Forth search order, that is naturally be present,
because Forth is the implementation language.
Traditional Forth implementation have a voc link, that points
to a previous wordlist, and allows Forth to print a list of
VOCABULARY's. It can be put to good use to implement the
chain of nested environments that lisp requires.

An environment is a wordlist, and a Forth mechanism can be used
to store lisp function in the wordlist.
That ties up the name field (to identify) and the link field (to
search).
Because it is a function defined in a high level Forth,
the code field contain docol, and the data field contains
a pointer to high level code.
The flag field is put to good use in identifying lisp
objects like numbers string symbols.

So the CDFLN fields are tied up, lisp functions run out of Forth header
fields.
Comes ciforth. The implementor of ciforth had the foresight to define
an extra field (>XFA) , free to use.

The bottom line is you can have a lisp closure call as follows:
\ Execute a lisp execution-token .
: EXECUTE-LISP DUP >XFA @ ENVIR ! EXECUTE ;

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: Closures

<2023Aug14.161756@mips.complang.tuwien.ac.at>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17445&group=comp.lang.lisp#17445

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: Closures
Date: Mon, 14 Aug 2023 14:17:56 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 28
Message-ID: <2023Aug14.161756@mips.complang.tuwien.ac.at>
References: <nnd$46df7f6f$350f7542@2161f37a21843b9e>
Injection-Info: dont-email.me; posting-host="81f33ac512e6dd79ae1ca3f4b44ae9a0";
logging-data="2491674"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cTj390ozMWUACthICBWJJ"
Cancel-Lock: sha1:OaZJeoY6FSjF/Cd5QdvK2buiGXQ=
X-newsreader: xrn 10.11
 by: Anton Ertl - Mon, 14 Aug 2023 14:17 UTC

albert@cherry.(none) (albert) writes:
>I finally understood what closures mean.
>In Forth parlance it is a search order that is kept with an
>Forth word.

That view leads down to boy compilers (in Knuth's man-or-boy test),
and at best (if you save and restore the variables on function entry
and exit) dynamically-scoped Lisp.

>An environment is a wordlist,

A wordlist has only one instance of each word in a wordlist.

An environment in a statically-scoped language is a set of local
frames, where each local frame is created dynamically when the
function to which the frame belongs is called. So if a function has
two instances at the same time (e.g., in recursion), a wordlist is
insufficient.

You can use wordlists to store the offsets of variable within the
frames, but you have to manage the frames separately.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2023: https://euro.theforth.net/2023

Re: Closures

<20230814082601.901@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17446&group=comp.lang.lisp#17446

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: Closures
Date: Mon, 14 Aug 2023 15:27:25 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <20230814082601.901@kylheku.com>
References: <nnd$46df7f6f$350f7542@2161f37a21843b9e>
Injection-Date: Mon, 14 Aug 2023 15:27:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e46a56cd35364bd395dd3d3fbcbd4bf2";
logging-data="2508344"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/v7CGJy7JBX/UYM53DSLGJag7F2AaYISE="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:gtfbkDSLQcKLzsi/TWmZocJhWNo=
 by: Kaz Kylheku - Mon, 14 Aug 2023 15:27 UTC

On 2023-08-14, albert@cherry.(none) (albert) <albert@cherry> wrote:
> I finally understood what closures mean.
> In Forth parlance it is a search order that is kept with an
> Forth word.

It seems as if you emigrated to Forth Island decades ago and now you
need everything translated into Forthese.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Closures

<ube8p1$2fvgt$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17447&group=comp.lang.lisp#17447

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dxforth@gmail.com (dxforth)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: Closures
Date: Tue, 15 Aug 2023 08:10:41 +1000
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <ube8p1$2fvgt$1@dont-email.me>
References: <nnd$46df7f6f$350f7542@2161f37a21843b9e>
<20230814082601.901@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 14 Aug 2023 22:10:41 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5f0f5740c4479f9cfe85ad23c2336d96";
logging-data="2620957"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/X80FU72ScVmzfhG1dp/tV"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.14.0
Cancel-Lock: sha1:kLQlFhWOsIVWKjmiUyhgc6OXU2c=
Content-Language: en-GB
In-Reply-To: <20230814082601.901@kylheku.com>
 by: dxforth - Mon, 14 Aug 2023 22:10 UTC

On 15/08/2023 1:27 am, Kaz Kylheku wrote:
> On 2023-08-14, albert@cherry.(none) (albert) <albert@cherry> wrote:
>> I finally understood what closures mean.
>> In Forth parlance it is a search order that is kept with an
>> Forth word.
>
> It seems as if you emigrated to Forth Island decades ago and now you
> need everything translated into Forthese.

Some concepts that abound are baffling and need translating.
OTOH forth afficionados come up with novelties too :)

Re: Closures

<20230814171803.23@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17448&group=comp.lang.lisp#17448

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: Closures
Date: Tue, 15 Aug 2023 00:20:44 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <20230814171803.23@kylheku.com>
References: <nnd$46df7f6f$350f7542@2161f37a21843b9e>
<20230814082601.901@kylheku.com> <ube8p1$2fvgt$1@dont-email.me>
Injection-Date: Tue, 15 Aug 2023 00:20:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="12961595d97071749275a1c93b8d4ac5";
logging-data="2653876"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/h3iVs0VKpKOecFWR83xrlPoUB+9cropQ="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:mFM3/9BllebSNeYjMMQELeCNwaE=
 by: Kaz Kylheku - Tue, 15 Aug 2023 00:20 UTC

On 2023-08-14, dxforth <dxforth@gmail.com> wrote:
> On 15/08/2023 1:27 am, Kaz Kylheku wrote:
>> On 2023-08-14, albert@cherry.(none) (albert) <albert@cherry> wrote:
>>> I finally understood what closures mean.
>>> In Forth parlance it is a search order that is kept with an
>>> Forth word.
>>
>> It seems as if you emigrated to Forth Island decades ago and now you
>> need everything translated into Forthese.
>
> Some concepts that abound are baffling and need translating.
> OTOH forth afficionados come up with novelties too :)

Large numbers of more or less empty heads that don't know anything other
than Javascript are able to grok closures.

Relating things to what you know is a useful crutch, but at
some point you have to just walk.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Closures

<nnd$72db704f$1f125581@4ee178c03f861ea4>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17449&group=comp.lang.lisp#17449

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Newsgroups: comp.lang.forth,comp.lang.lisp
References: <nnd$46df7f6f$350f7542@2161f37a21843b9e> <2023Aug14.161756@mips.complang.tuwien.ac.at>
Subject: Re: Closures
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$72db704f$1f125581@4ee178c03f861ea4>
Organization: KPN B.V.
Date: Tue, 15 Aug 2023 08:44:44 +0200
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 67
Injection-Date: Tue, 15 Aug 2023 08:44:44 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 3452
 by: none - Tue, 15 Aug 2023 06:44 UTC

In article <2023Aug14.161756@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>albert@cherry.(none) (albert) writes:
>>I finally understood what closures mean.
>>In Forth parlance it is a search order that is kept with an
>>Forth word.
>
>That view leads down to boy compilers (in Knuth's man-or-boy test),
>and at best (if you save and restore the variables on function entry
>and exit) dynamically-scoped Lisp.
I'm an amateur. I implement MAL. I don't know whether that is a
dynamically-scoped Lisp. Actually my goal is to prove that
Forth is capable of parsing lisp itself, with a modular parser
in the style of BEGIN WHILE REPEAT words.
For example the rule that comma is to be treated as blank space
translate to the rule:
: , ; PREFIX

>
>>An environment is a wordlist,
>
>A wordlist has only one instance of each word in a wordlist.
Okay, so we have multiple instance of a wordlist.

>
>An environment in a statically-scoped language is a set of local
>frames, where each local frame is created dynamically when the
>function to which the frame belongs is called. So if a function has
>two instances at the same time (e.g., in recursion), a wordlist is
>insufficient.
That would mean that
(def! fib (fn* (N) (if (= N 0) 1
(if (= N 1) 1 (+ (fib (- N 1))
(fib (- N 2)))))))
would fail, but it isn't:
(fib 10)
89

Also the quine tests succeeds. It was commented out of the tests,
because the line was too long. (and it is too long for a usenet post,
sorry). That was not a restriction in my implementation.

;;;;; Test quine
((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
;=>((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))

What fails is:
( ( (fn* (a) (fn* (b) (+ a b))) 5) 7)
(b) (+ a b))) 5) 7) ? ciforth ERROR # 8010
Error 8010 means that a symbol is not found in the nested environments.
`` a '' is not found.
The phrase clearly means that in the environment that `a has the
value 7, a new instance of the function has to be generated.
>
>You can use wordlists to store the offsets of variable within the
>frames, but you have to manage the frames separately.
I think I do with the proposed mechanism.
We shall see.

>
>- anton
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: Closures

<20230815002701.354@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17450&group=comp.lang.lisp#17450

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: Closures
Date: Tue, 15 Aug 2023 07:33:15 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <20230815002701.354@kylheku.com>
References: <nnd$46df7f6f$350f7542@2161f37a21843b9e>
<2023Aug14.161756@mips.complang.tuwien.ac.at>
<nnd$72db704f$1f125581@4ee178c03f861ea4>
Injection-Date: Tue, 15 Aug 2023 07:33:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="12961595d97071749275a1c93b8d4ac5";
logging-data="2880648"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18i7jSUMV48hTAjCLC+KF1pHmrVPgT5PYo="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:TQ7j5sOcmrN6fZjP3ZPl1+BBB40=
 by: Kaz Kylheku - Tue, 15 Aug 2023 07:33 UTC

On 2023-08-15, albert@cherry.(none) (albert) <albert@cherry> wrote:
> That would mean that
> (def! fib (fn* (N) (if (= N 0) 1
> (if (= N 1) 1 (+ (fib (- N 1))
> (fib (- N 2)))))))
> would fail, but it isn't:
> (fib 10)

fib is not capturing lexical closures. There are multiple instances, but
they are not accessible at the same time. In particular, once any
activation of fib terminates, nothing accesses that instance of N any
more.

We can write fib in C, whose local variables turn to pixie dust when the
block scope ends, allowing a simple stack to be used for locals.

Lexical closures mean that the variables visible in any activation of a
function can live indefinitely. Lexical closures are objects that can
escape from the context where they are created, and be invoked after
that context has terminated.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Closures

<nnd$20f8c05f$1a111f26@3a908af20343f57f>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17451&group=comp.lang.lisp#17451

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Newsgroups: comp.lang.forth,comp.lang.lisp
References: <nnd$46df7f6f$350f7542@2161f37a21843b9e> <2023Aug14.161756@mips.complang.tuwien.ac.at> <nnd$72db704f$1f125581@4ee178c03f861ea4> <20230815002701.354@kylheku.com>
Subject: Re: Closures
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$20f8c05f$1a111f26@3a908af20343f57f>
Organization: KPN B.V.
Date: Tue, 15 Aug 2023 10:40:54 +0200
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 38
Injection-Date: Tue, 15 Aug 2023 10:40:54 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2402
 by: none - Tue, 15 Aug 2023 08:40 UTC

In article <20230815002701.354@kylheku.com>,
Kaz Kylheku <864-117-4973@kylheku.com> wrote:
>On 2023-08-15, albert@cherry.(none) (albert) <albert@cherry> wrote:
>> That would mean that
>> (def! fib (fn* (N) (if (= N 0) 1
>> (if (= N 1) 1 (+ (fib (- N 1))
>> (fib (- N 2)))))))
>> would fail, but it isn't:
>> (fib 10)
>
>fib is not capturing lexical closures. There are multiple instances, but
>they are not accessible at the same time. In particular, once any
>activation of fib terminates, nothing accesses that instance of N any
>more.

Obviously not, I observed that. The test for capturing lexical closures
fails, but fib is not.

<SNIP>
>Lexical closures mean that the variables visible in any activation of a
>function can live indefinitely. Lexical closures are objects that can
>escape from the context where they are created, and be invoked after
>that context has terminated.
This is lisp parlance. The concept of lexical closures is present
in algol 68, but the term is not used.
Any language that supports functions within functions, functions as
first order objects and persistance (items created in a function that
have a life span longer than the function call) has this feature.

>Mastodon: @Kazinator@mstdn.ca

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor