Am 27.04.2021 um 19:56 schrieb Michael Van Canneyt via fpc-pascal:
On Tue, 27 Apr 2021, Ryan Joseph via fpc-pascal wrote:
On Apr 27, 2021, at 9:58 AM, Michael Van Canneyt
<mich...@freepascal.org> wrote:
Wait.
I asked Sven to make sure that nested functions are under ALL
circumstances
usable as closures or can be used instead of anonymous functions.
Pas2js already supports this, and I want FPC and Pas2JS to be
compatible in
this regard.
So as Sven wrote, you would be duplicating effort, needlessly, since
it has
to work always... If the compiler can decide that the heap interface
is not
needed and optimize it away: so much the better. But I doubt this
will be
possible.
Maybe we're misunderstanding each other then. I'm responding to Sven
when he says:
Getting rid of the interface only works in very narrow circumstances
that are so seldom in real world code that it is not worth the effort.
I.e. all closures will be interface based because there are not enough
real world use cases to support any alternative. Which is contrary to
what you're saying that nested functions/closure will be compatible
types.
Why is this contrary ?
As I understand it:
a closure is used for arguments of type 'reference to procedure'.
In delphi, this procedure can be a real method or an anonymous function.
So why should you not be able to use a local function instead of an
anonymous function ?
How the closure is implemented internally is irrelevant from the
programmer's point of view. As long as the signature is correct,
presumably the compiler can figure out what needs to be done: create
an interface (with all that implies) or not.
It will *always* create an interface. It's just how the compiler will
wrap it.
Regards,
Sven
PS: And who was the one who switched to fpc-pascal? O.ó
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal