[fpc-devel] Delphi anonymous methods

Martin lazarus at mfriebe.de
Mon Mar 4 22:41:28 CET 2013


On 04/03/2013 19:16, Alexander Klenin wrote:
>> See above. The omission "of Result :=" is IMHO not desirable.
> Are you sure? Note that *any* useful single-statement function will
> start exactly like this
If a = x then Result := 4 else Result := 5;

Single statement, but starts different.  And is useful.

But that isn't why I replied again.

Reading the shortened version versus the full anonymous procedure (with 
var, const, type....) and I realized, that thi's a 2 entirely different 
things.

The above is NOT an anonymous function. It is a reference to a term.
I am not voting for it, but IF it was done, then it should have its own 
keyword.

It would not allow for var, type or anything (and it will only work for 
functions, not procedures.)
    a.sort(LambdaTerm TMyCompare do x > y)
or
    a.sort(TermRef TMyCompare(x > y) )

anonymous function, then would *always* require
    a. sort( Function; prototype TMyCompare; [var ...] begin ... end )

the protopybe (modifier) could work for named procedures too. (THey 
would be required NOT to have any params)
   Function Foo; prototype TMyCompare;
   [var ...]
   begin ... end




More information about the fpc-devel mailing list