[fpc-pascal] Re: Delphi's anonymous functions in Free Pascal

Florian Klämpfl florian at freepascal.org
Wed Oct 19 20:04:08 CEST 2011

Am 19.10.2011 10:16, schrieb Sven Barth:
> Am 19.10.2011 09:31, schrieb Michael Fuchs:
>> I would prefer a style like
>> myfunc := @function(x, y: Integer): Integer Result := x + y;
> And how would you create more complex functions? In Pascal code blocks
> are started with "begin" and ended with "end". I don't see a reason why
> anonymous methods should differ here.
> Also the example given by Embarcadero is a bit boring. The interesting
> thing about anonymous methods (and nested functions types in FPC) is
> that they can access variables of the surrounding function (at least I
> hope that I've understand it correctly that nested function types can do
> that).

The main difference between anonymous methods and nested functions is
that one can return a reference to an anonymous method from a function,
the anonymous method can access local variables from that function and
even after exiting the function, the variables are still valid. This
means that local variables accessed in a anonymous method end up on the

However, I fail to see reasonable use cases for anonymous methods

More information about the fpc-pascal mailing list