[fpc-devel] Closures via interfaces
kevroletin at gmail.com
Sun May 26 12:12:47 CEST 2013
About 2 months ago there was a big discussion about closures(thread
"Delphi anonymous methods"). After this discussion I started work on
Delhi-like closures for fpc. I am far from finish and current
implementation is not perfect. But I already have positive results: it's
possible to declare and use anonymous functions. After few changes
closures will be able to capture variables. I created mantis#24481 to
handle this work. Everyone who is interested in closures and good in
compiler is welcome into mantis. I would be happy if someone looked into
changes and said few words.
I described details of proposed and partly implemented approach in
mantis. This is Delphi's approach. Some people call it "closures via
interfaces". In slightly modified way it will allow to capture variables
by value (which was requested in previous discussion). I like this
approach because it's simple: it doesn't require to change codegenerator
or rtl. On the other hand for each closure it creates new interface. And
almost for each closure it creates new class. As a result: space
overhead because of virtual tables and rtti.
My question to community is: what do you think about proposed
implementation? Are there arguments for another approach?
More information about the fpc-devel