[fpc-pascal] Re: Delphi's anonymous functions in Free Pascal

Alexander Shishkin alexvins at mail.ru
Sun Nov 6 14:00:34 CET 2011


06.11.2011 15:53, Florian Klämpfl пишет:
> Am 05.11.2011 22:58, schrieb Alexander Shishkin:
>> 06.11.2011 1:46, Michael Van Canneyt пишет:
>>>
>>>
>>> On Sat, 5 Nov 2011, Bernd wrote:
>>>
>>>> 2011/10/25<michael.vancanneyt at wisa.be>:
>>>>
>>>>>> targethread.queue(
>>>>>>   procedure(targetobject:ttargetobject;a:integer;b:someobject;c:string)
>>>>>>              begin
>>>>>>                targetobject.destinationprocedure(a,b,c);
>>>>>>              end;
>>>>>>
>>>>>> Note how common this looks compared to the original.
>>>>>
>>>>> One point is that you could do the above with a local (and named)
>>>>> procedure
>>>>> as well, and still have all the context. At the very least you would
>>>>> not be
>>>>> raping pascal's readability by putting a
>>>>> complete procedure declaration inside a code block.
>>>>
>>>> How would you preserve the context without finding some place
>>>> somewhere (on the heap) to store the current values of a, b, and c?
>>>>
>>>
>>> Procedure SomeOuter;
>>>
>>> Var
>>> d,e,f : SomeType;
>>>
>>> Procedure
>>> SomeInner(targetobject:ttargetobject;a:integer;b:someobject;c:string)
>>>     begin
>>>       targetobject.destinationprocedure(a,b,c);
>>>     end;
>>>
>>> begin
>>> Targethread.queue(@SomeInner(aobject,d,e,f));
>>> end;
>>>
>>> No difference with 'closure', except more readable.
>>>
>>
>> Closures can be returned as a function result but nested procedure not
>> (more strictly, this can be complied but will not work because of
>> lifetime of nested procedure).
>
> Of course, but what Michael means is: closure support does not require
> necessarily anonymous proceudures/functions/methods.
>
> It would be probably more clear to write and this more pascalish:
>
> Procedure SomeOuter;
>
> Var
>    d,e,f : SomeType;
>
>    Lambda Procedure
> SomeInner(targetobject:ttargetobject;a:integer;b:someobject;c:string)
>    begin
>       targetobject.destinationprocedure(a,b,c);
>    end;
>
> begin
>    Targethread.queue(@SomeInner(aobject,d,e,f));
> end;
>
> We don't need lambda expressions after all to implement controll
> statements like e.g. smalltalk.
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>
OK, agreed, this is more readable than Delphi syntax. But ...
1) If we implement lamdas is FPC we will have to support Delphi syntax.
2) lambda systax is usually as short as possible, but this is not 
"pascalish".




More information about the fpc-pascal mailing list