Answer the question
In order to leave comments, you need to log in
Anonymous methods, closures. Can you explain an example?
I quote:
As the name suggests, anonymous methods are procedures or functions that do not have an associated name. An anonymous method is a block of code that can be associated with a variable or used as a parameter to another method. In addition, anonymous methods can use variables from the context where the method is defined. Declaring and using anonymous methods does not require complex syntax. Their syntax is similar to the construction of closures (closures), characteristic of other programming languages.
function MakeAdder(y: Integer): TFuncOfInt;
begin
Result := function(x: Integer)
begin
Result := x + y;
end;
end;
var
adder: TFuncOfInt;
begin
adder := MakeAdder(20); // что происходит тут ?
Writeln(adder(22)); // prints 42 // и тут ?
end.
type
TFuncOfInt = reference to function(x: Integer): Integer;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question