[fpc-devel] Question about Syntax: I there a reason for this design?
Boian Mitov
mitov at mitov.com
Sun Sep 21 19:45:46 CEST 2014
Hi Jonas,
I actually agree that it is a nice feature, and I want to have it both in
Delphi and FPC :-) .
I prefer the anonymous method syntax as it means less typing, and typing is
expensive, however there are cases when I really would love to capture local
function. I had few of them already.
The problem is even bigger. You can't even call a local function from
anonymous method doe to the same capturing issue :-( . This really should
have been addressed in Delphi.
With best regards,
Boian Mitov
-------------------------------------------------------
Mitov Software
www.mitov.com
-------------------------------------------------------
-----Original Message-----
From: Jonas Maebe
Sent: Sunday, September 21, 2014 10:23 AM
To: FPC developers' list
Subject: Re: [fpc-devel] Question about Syntax: I there a reason for this
design?
[Jonas: anonymous methods and local functions could use the same syntax]
I'm talking about syntax, not behaviour. When assigning a local function
to an anonymous method ("reference to ..."), the context will have to be
captured in exactly the same way as when specifying an inline nested
function (aka anonymous method) that requires context. A nested function
and a "reference to..." are different types, so a type conversion would
have to be inserted by the compiler anyway (a bit similar to how
assigning a method to a "procedure of object" works, which also captures
context, be it in a much simpler way).
You could still first keep the context on the stack for quick access by
the parent function and later add indirection if necessary (in case it
can escape the life of the parent function), as handled by e.g. C blocks.
More information about the fpc-devel
mailing list