> On Apr 27, 2021, at 2:23 PM, Ryan Joseph <generic...@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

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to