[fpc-devel] Delphi anonymous methods

Alexander Klenin klenin at gmail.com
Tue Mar 5 12:29:14 CET 2013


On Tue, Mar 5, 2013 at 9:10 PM, Paul Ishenin <paul.ishenin at gmail.com> wrote:
> 05.03.13, 17:55, Sven Barth wrote:
>
> I see you, Graeme, Michael and probably some more 5-6 developers.
>
The level of Delphi compatibility vs. syntax quality is, as always in
engineering,
a matter of compromise and cost/benefit analysis.
For example, and trying to return to the topic of this thread,
I think "embedded" anonymous functions should be implemented for both
Delphi and ObjFPC mode --
even if there will be better alternatives in ObjFPC.
This way, at least in one direction compatibility will be preserved,
while people preferring "pure Pascal" style will still be able to
ignore Delphi syntax in their FPC-only projects.
On the other hand, default closure behavior should perhaps be
implemented differently.
There are three choices for anonymous function without additional annotations:
1) No closure
2) By-reference closure
3) By-value closure

Delphi currently implements (2) which is inconsistent with nested
functions and introduces a subtle
and unexpected performance drop. I suggest (1) in ObjFPC mode, but (2)
in Delphi mode,
with additional modeswitch, as usual.

This is why I propose the following plan:

1) Implement Delphi-like anonymous functions syntax, without closures
2) Implement Delphi-like by-reference closures
3) Implement ObjFPC-specific named closures with explicit by-value/by
reference options
4) Implement ObjFPC-specific shortened syntax

Discussion of ObjFPC extension may continue while the implementation
of (1) and (2) is in progress.

--
Alexander S. Klenin



More information about the fpc-devel mailing list