Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Lambda functions in Delphi

Tags:

lambda

delphi

I have a question about lambda function.

In example below the code it is a lambda function in Delphi?

var
  Lambda: TFunc<Integer, Integer>;
begin
  Lambda:= function(ANumber: Integer) : Integer
           begin
             Result:= ANumber * ANumber;
           end;


   ShowMessage(Lambda(2).ToString());
   ShowMessage(Lambda(4).ToString());
end;

Thanks

like image 978
Johni Douglas Marangon Avatar asked Sep 17 '14 18:09

Johni Douglas Marangon


1 Answers

In Delphi terminology that is an anonymous function. In some languages they are known as Lambda functions. So yes, this is a Lambda function.

This is Wikipedia's take on the subject: http://en.m.wikipedia.org/wiki/Anonymous_function

like image 185
David Heffernan Avatar answered Nov 15 '22 04:11

David Heffernan