[fpc-devel] Delphi anonymous methods

Martin lazarus at mfriebe.de
Mon Mar 4 12:34:03 CET 2013


On 04/03/2013 05:57, Alexander Klenin wrote:
> On Mon, Mar 4, 2013 at 2:38 PM, Martin <lazarus at mfriebe.de> wrote:
>
>> Closures, do not need to be written/declared in the middle of other code
>> (in-line)
> Strictly speaking, they do not. However, if the closures are required
> to be named,
> their expressive power and readability will suffer greatly.
>
>
> Nevertheless, I agree what the implementation plan can be detailed even further:
> 1) Anonymous procedures *without* closures -- basically, just another
> syntax for nested procedures.
That might be interested for mode Delphi
> 2) Named closures support -- while I do think that anonymous
> procedures are useful,
And this could be in mode FPC too. So "purists" can still enjoy 
closures. But it keeps one of the thinks that make Pascal: Declaration 
is all done before the code block starts.

> 3) Anonymous closures support -- a combination of the above:
>     // Delphi-compatible syntax. Could be made to *not* use closures in
>
> 4) As stated above, either a syntax to explicitly turn off a closure
> for anonymous procedure,
>    or intelligent enough optimizer to do that automatically. I have
> some ideas on both fronts,
>    but I suggest we first discuss previous points.
>

IMHO explicit Syntax.

But in the recent light of discussions to keep pascal being Pascal, 
anonymous functions could be entirely mode delphi only.

 From the reasons for anonymous methods.
>    in Delphi every local variable access becomes a reference to the
> frame object field,
>    *even in the parent procedure*. So "nested" anonymous procedures,
> together with
>    good inlining support, are crucial for the efficient implementation
> of, for example,
>    various "ForEach" methods.

That could be implemented for *named* closures too, and then there was 
no need for the anonymous.


IMHO anonymous methods are a syntactical difference only. All 
functionality can be done with named equivalents too.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20130304/8c482bd8/attachment.html>


More information about the fpc-devel mailing list