[fpc-pascal] [fpc-devel] Nested function closures

Sven Barth pascaldragon at googlemail.com
Thu Apr 29 08:01:02 CEST 2021


Ryan Joseph via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Mi., 28. Apr. 2021, 17:53:

>
>
> > On Apr 27, 2021, at 11:36 PM, Sven Barth <pascaldragon at googlemail.com>
> wrote:
> >
> > Anyway, it would in principle be possible to convert an anonymous
> function to a "is nested" function, but that will only come *after* the
> whole implementation is here so that the chance for messing that core
> functionality (!) up is reduced.
>
> Sorry I'm struggling with all these new terms myself. Yes that is what I'm
> proposing and what I demonstrated in that GitHub branch. We talked about
> this in 2018 but you said to wait until the "real thing" was finished so I
> let it be. I brought this up again now to say that when, and not before,
> the closures are finished and in trunk I will see how to integrate the
> "nested anonymous functions" into the new system.
>
> To clarify for myself, we have a few concepts here:
>
> - Closures: blocks which capture variables in scope and wrap them into a
> container (nested functions use a record I think and closures will use an
> interface).
>

Nested functions simply use the framepointer. They are using it like a
record, but in essence it's simply the framepointer...

- Anonymous procedures: Simply an anonymous procedure/function body which
> lacks a name and can be declared inside code blocks.
>

Correct.

- 2 Procedure types: "reference to" and "is nested". On the caller side
> these are what control which kind of closure is used is used. Is that
> correct? So the anonymous function doesn't really become a closure until
> it's passed to a "reference to" or "is nested" variable.
>

To be precise there are two more: function/procedure variables (no special
designator) and method variables ("of object"). Depending on what a
anonymous function captures (or for the sake of it a nested function) it
would be possible to assign it to such a type as well (for a function
variable only global variables may be used, for a method variable
additionally Self may be used).

So once the current work is done we have 2 kinds of closures but only one
> of those is compatible with anonymous functions and this is why I want the
> other closures (nested functions) to have the same pair of functionality.
>

Once anonymous functions are supported we can improve their compatibility
with other constructs.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210429/28d58f8d/attachment.htm>


More information about the fpc-pascal mailing list