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

Bernd prof7bit at googlemail.com
Sun Nov 6 12:41:58 CET 2011


2011/11/6 Michael Van Canneyt <michael at freepascal.org>:

> I am not against closure functionality, although I highly doubt it is *that*
> useful as some people make it out to be. Even so, I use it in my Javascript
> programming.

I'm also not entirely sure about the necessity of closures in OP, but
I must admit I am not totally against it. I am somewhat undecided.
Since we have objects we can easily port every algorithm that needs
closures 1:1 to OP without changing anything, we just have to put a
ton of type definition boilerplate in front of it but the algorithm
itself will look and work 100% the same. It will just pass objects
around instead of closures (and in some simple cases where we don't
need to enclose data we can take the shortcut and use a procedure
variable).

In Javascript there is no difference between 'object' and 'function',
they are the same thing, every function is an object, creating
functions and passing them around is a totally normal thing in JS,
just as normal as it is in OP to create Instances of classes and pass
them around.

But I cannot totally deny that closures in OP would be a cool feature.
They are not necessary to do what can already be done but they still
would be an extremely cool feature which can increase the
expression/noise ratio significantly in some cases if used
appropriately.

And I believe eventually they will be implemented in FPC. I have
absolutely no doubt.


BTW: Here is a post I found while googling for Delphi examples, he
explains the approach they took in Delphi:
http://compilers.iecc.com/comparch/article/09-04-067



More information about the fpc-pascal mailing list