Recent

Author Topic: Anonymous Methods  (Read 40243 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Anonymous Methods
« Reply #45 on: July 29, 2014, 04:39:48 pm »
Since it seems Embarcadero approaches foreign targets more as target for client apps, well, with Steam Linux might now also get an interesting Store concept to target, since that seems to be Emb's business now.

OTOH "looking at Linux" has been on their todo (long term roadmap) list since Delphi 2009 now. I'm not sure it is even on it, haven't been at recent press events. (after XE3)




thijsvandien

  • Newbie
  • Posts: 2
Re: Anonymous Methods
« Reply #46 on: February 01, 2015, 12:40:35 am »
The initial question was to provide a use case. Here is one that I'd like.

Code: [Select]
procedure WithBusyCursorDo(AProc: TProc);
var
  LOldCursor: TCursor;
begin
  LOldCursor := Screen.Cursor;
  Screen.Cursor := crHourGlass;
  try
    AProc;
  finally
    Screen.Cursor := LOldCursor;
  end;
end;

procedure PerformSlowOperation;
begin
  WithBusyCursorDo(procedure
  begin
    // Take your time...
  end);
end;

It nicely cleans up frequently used try-finally-end blocks and it would be ugly to have to define a nested procedure first like this:

Code: [Select]
procedure PerformSlowOperation;
  procedure _PerformSlowOperation;
  begin
    // Take your time...
  end;
begin
  WithBusyCursorDo(_PerformSlowOperation);
end;

Especially when the list of statements gets longer, and thus the nested procedure will be huge compared to the rest. However, the latter doesn't even work.
« Last Edit: February 01, 2015, 03:36:23 am by thijsvandien »

Nashev

  • Newbie
  • Posts: 5
Re: Anonymous Methods
« Reply #47 on: June 18, 2015, 01:04:08 pm »
What progress in discussion about Closures and anonimous methods in fpc are now?
Why no answer to requested sample from @thijsvandien?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Anonymous Methods
« Reply #48 on: June 18, 2015, 01:11:32 pm »
What progress in discussion about Closures and anonimous methods in fpc are now?

Still the same.

Quote
Why no answer to requested sample from @thijsvandien?

Because there is nothing to answer.  The main discussion is who is going to do it, not yes or no or why.

Nashev

  • Newbie
  • Posts: 5
Re: Anonymous Methods
« Reply #49 on: June 18, 2015, 01:25:17 pm »
Does it mean Yes?

Nashev

  • Newbie
  • Posts: 5
Re: Anonymous Methods
« Reply #50 on: June 18, 2015, 01:43:39 pm »
To readers like me, see also
  • newer topic http://forum.lazarus.freepascal.org/index.php?topic=28617.0 at June 02, 2015:
    Quote
    Has there been any movement on anonymous method support in FPC? I've heard rumors that something is in the works but haven't been able to find any announcements.
  • http://forum.lazarus.freepascal.org/index.php?topic=25933.0 at September 24, 2014:
    Quote
    I am now in the process of porting QTX Pascal and, if possible, Smart Mobile Studio to FPC/LAZ. But for some reason, even the simplest code using anonymous methods refuse to compile? I especially use it with delayed execution. Like this: w3_callback( procedure () Begin //do this in 1000 ms end,  1000);
  • http://forum.lazarus.freepascal.org/index.php/topic,24261.msg146023.html#msg146023 etc at April 17, 2014:
    Quote
    In the interview it mentioned "The next big thing for FPC will be the 3.0 release: Besides a lot of new language features...", doesn't anybody know if the upcoming FPC 3.0 will support anonymous method? I've done some search, the newsletter archives of 2013 show that it's been discussed and someone's been working on it in a branch, but couldn't find any definite info. Anonymous method 's "local variable capturing" allows us write more clean code logics, and you'll gonna love it if you use it in practice :)
  • http://forum.lazarus.freepascal.org/index.php/topic,25068.msg151655.html#msg151655 at July 03, 2014:
    Quote
    - functional languages: have been around and had staunch proponents for ages, mostly in math departments.  Closures like construct being easier to divide over threads makes some people believe the next big thing is functional. I don't think so, simply because fully functional programming is too hard to introduce large scale. I think it will be experiments like LINQ (which nevertheless can be useful in domain specific cases, I just don't think it is really a big general programming advantage) and adding some form of continuation to nearly every existing language. Even Delphi has anonymous functions. I think the rest of functional languages will stay in university math departments and their startups.
  • http://forum.lazarus.freepascal.org/index.php/topic,8292.msg39963.html#msg39963 at January 05, 2010:
    Quote
    Not without using higher level concepts than those normally used in Pascal, such as the ability to treat language expressions as first class elements in the language (so you can basically pass a reference to an expression as parameter). It might also be possible to implement this sort of things based on whatever infrastructure is required for anonymous functions/closures, but FPC doesn't support any of that yet.
  • http://forum.lazarus.freepascal.org/index.php?topic=16693.0 at April 20, 2012:
    Quote
    Now FPC related.  If there is one area I really hope FPC dev's get sorted, it's got to be closures (or in Delphi dialect Anonymous methods).  In a world where multi-processor programming now is really the norm, having these sorted is really a must.
  • http://forum.lazarus.freepascal.org/index.php/topic,16754.msg91579.html#msg91579 at April 27, 2012:
    Quote
    I was actually thinking of creating a generic Worker Thread / Pool Manager for making threading a lot easer in Lazarus, unless I'm missing it I don't see any thread managers currently in Lazarus.  Ideally FPC and closures would make Threading even easer, but I think that's still under development.
  • http://free-pascal-general.1045716.n5.nabble.com/Delphi-compatible-anonymous-functions-td5719246.html at May 15, 2014:
    Quote
    I've been experimenting with anonymous functions in FPC and have working code, but they're not at all like what Delphi provides:

    https://github.com/tangentstorm/tangentlabs/blob/master/pascal/funops.pas

    (On the other hand, they require 0 compiler changes...)

    I asked about lambdas in the IRC channel a few months back, and Sven told me someone had started work on anonymous methods sometime in the past, but the work sort of stalled out.

    If you're interested in funding this and nobody else pipes up, I'm interested in implementing it. It's something I've been wanting to do anyway, but I just haven't had the time/energy to dig into the FPC internals.
  • http://stackoverflow.com/questions/7799077/how-can-i-use-anonymous-methods-in-free-pascal
  • http://wiki.freepascal.org/delphi_language_features_which_fpc_does_not_have#Anonymous_Methods
« Last Edit: June 18, 2015, 03:54:05 pm by Nashev »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Anonymous Methods
« Reply #51 on: June 18, 2015, 08:25:21 pm »
I already summarized the situation in the first quote you name (the most recent discussion till this was revived) http://forum.lazarus.freepascal.org/index.php/topic,28617.msg179217.html#msg179217

Afaik sb worked on a branch, but I could only find an old message. Seems that that branch hasn't been worked on since 2012:

http://lists.freepascal.org/fpc-devel/2013-March/031564.html

Sb picked it up in 2013 and worked on github, but that also seems to have stalled:

https://github.com/vkevroletin/freepascal/tree/closures-via-interfaces

So in short, it seems the 3rd party progress has stopped, and nobody is actively working on it to my best knowledge.

marines

  • Newbie
  • Posts: 1
Re: Anonymous Methods
« Reply #52 on: October 08, 2015, 08:39:26 pm »
anymous methods exist in objective-c, c++, java, c# and object pascal
we would be more than happy to migrate to fpc if we had them in 3.x branch
seems to me that compiler engineers need convincing... i know it's not easy to preserve the state of lambda vards, but still...

ps :-)
deprecate all delphi compiler features, same about tp, go back to nicholas wirdth (that is a very clean pascal dialect)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Anonymous Methods
« Reply #53 on: October 08, 2015, 08:46:46 pm »
seems to me that compiler engineers need convincing... i know it's not easy to preserve the state of lambda vards, but still...
believe it or not but anonymous methods are in the compiler already. For example in form of blocks, needed for ObjC compatibility.

But there're 3 ways to convince compiler engineers:
* provide a good (well-written, clean) patch, that someone else could maintain (because there's a high chance that an author of the patch will not maintain it)
* money
* the code of the compiler itself has to use anonymous methods

The team is on the course of finishing the existing features, rather than introducing new ones.

anymous methods exist in objective-c, c++, java, c#
Not enough reasoning. Let me explain:
Inline assembler doesn't exist in java ... should it be removed from FPC?
C++ has 18 levels of operator precedence ... should they be added to FPC?
C# is tightly bound to MS .NET frameworks... should the same restriction be added to FPC?

The presence/absence of a feature in one language, isn't not a reason for another language to add/remove it.
« Last Edit: October 08, 2015, 08:53:07 pm by skalogryz »

 

TinyPortal © 2005-2018