[fpc-pascal] [fpc-devel] Nested function closures
Ryan Joseph
genericptr at gmail.com
Tue Apr 27 23:13:29 CEST 2021
> On Apr 27, 2021, at 2:23 PM, Ryan Joseph <genericptr at gmail.com> wrote:
>
> But why would it do that when we could use an alternate code path that uses nested functions instead? Maybe I'm not being clear but we can do BOTH depending the situation when one is better than the other. This is just an optimization that leverages existing features that are already in the compiler anyways. Seems like a no-brainer to me.
Here's what I'm proposing. Closures and nested functions should be symmetrical so that anonymous function bodies can be used without relying on the interfaces when they're not needed.
type
TComparator = procedure (a, b: TEntity): Integer is nested;
procedure TMyClass.SortEntities(comparator: TComparator);
begin
end;
for i := 0 to entities.Count - 1 do
begin
value := entities[i];
value.SortEntities(function(a, b: TEntity): integer
begin
// do stuff
end
);
end;
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list