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

Sven Barth pascaldragon at googlemail.com
Wed Apr 28 07:32:08 CEST 2021


Am 28.04.2021 um 00:53 schrieb Graeme Geldenhuys via fpc-pascal:
> On 27/04/2021 10:13 pm, Ryan Joseph via fpc-pascal wrote:
>>       value.SortEntities(function(a, b: TEntity): integer
>>         begin
>>           // do stuff
>>         end
>>       );
> It seem the beginning of the thread is missing, but I would like to
> comment on something here - purely based on the example code given.
>
> The SortEntities() is defined with a signature of type TComparator,
> which in turn is a function that takes 2 arguments of type TEntity
> and returns a integer.
>
> Why must the anonymous function repeat all that information again,
> as shown in the quoted code above? Can't the compiler figure all
> that out simply by inference? All the developer should have to do
> is give the 2 parameters a name, and a function body (block of
> code). Thus you could end up with something like this:

First: Pascal does not support type inference which would be required 
for this.

Second: the syntax is required for Delphi compatibility anyway - and the 
main idea *is* to be able to use libraries like Spring4D or 
OmniThreadLibrary in FPC so I don't want *anyone* to whine about this, 
thus it makes no sense to introduce a new syntax (as much as I'd love to 
as well).

Regards,
Sven


More information about the fpc-pascal mailing list