[fpc-devel] Delphi anonymous methods
Martin
lazarus at mfriebe.de
Mon Mar 4 16:10:14 CET 2013
On 04/03/2013 14:49, Sven Barth wrote:
> Am 04.03.2013 15:42, schrieb Martin:
>>
>>> but (4) is powerful enough to really make functional-style programming
>>> practically
>>>
>>
>> I can live with that. I find it odd so that "as" is used in the
>> reverse order compared to current use.
>
> The use of "as" is based on an idea of mine. C# for example has "=>"
> and Oxygene has "->" which I didn't consider much Pascal like. Also
> the compiler needs to know the type of the lambda so it can correctly
> typecheck its code (after all we have no type inference (yet :P )). So
> "lambda PROCVARTYPE as EXPR/STMT" came as the most "natural" and
> Pascal like variant.
First: Stressing out: I don't like it. But if we must have one, the
lambda approach is the best one yet.
Reason: At least the type is declared at a pascal-like location.
I did not note at first, but the al leaves the "Result" away. So X+5
now looks like a statement.
What would happen with
ATree.VisitPreorder(lambda TVisitor as begin X := min(10,x); X + 5; end);
Reminds me of perl: the last value is the return value.
If you look for the most natural, pascal like (ignoring the part that declaring a function inline, IMHO is not that)
ATree.VisitPreorder(TVisitor(Result := X + 5);
ATree.VisitPreorder(TVisitor(begin Result := X + 5; end);
You are type casting the code, into a procedure of the given type.
More information about the fpc-devel
mailing list