[fpc-pascal] Delphi compatible anonymous functions

Craig Peterson craig at scootersoftware.com
Fri May 16 19:00:59 CEST 2014


On 5/16/2014 11:18 AM, Florian Klämpfl wrote:
> Isn't using anonymous methods in this case only a work around for missing OpenMP support?

Absolutely, but neither Free Pascal nor Delphi implement OpenMP.  The
OpenMP page on the Free Pascal wiki hasn't been significantly changed
since 2008, which coincidentally is the last time Allen Bauer blogged
about his "Delphi Parallel Library".  I'm looking for something that I
can use soon, not in 5 years.

Also, while I prefer the OpenMP proposals in the wiki, I don't see us
dropping Delphi for Lazarus on Windows anytime soon.  Short term we'll
be too busy moving our Linux version over from Kylix and then re-porting
our OS X version from LCL/Carbon to LCL/Cocoa.

> I still don't get how closures/anonymous methods help you to get rid of fibers? I mean, anonymous
> methods are only a short cut; closures allow you to capture the state of the variables of the outer
> scope even if the outer scope is left. But that's it?

No, it doesn't completely replace fibers.  That will require some very
painful detangling and much uglier, asynchronous code.  However, a
majority of the usage is just doing calculations, showing a dialog, then
doing something with the dialog results.  In cases like that it should
be relatively easy to do fairly mechanical conversions to something
based on anonymous methods and closures.

I'm not sure what you mean by the "But that's it?" though.  Yes, they're
just syntax sugar.  The alternative is creating a second procedure
(polluting the namespace), declaring, allocating, and initializing a
record with the local state, then passing it to that second function.
It's doable, and that's exactly what we did before I implemented the
fiber support, but it's certainly not ideal.

-- 
Craig Peterson
Scooter Software




More information about the fpc-pascal mailing list