Recent

Author Topic: Feature announcement: Function References and Anonymous Functions  (Read 92532 times)

deadserious

  • New Member
  • *
  • Posts: 25
Re: Feature announcement: Function References and Anonymous Functions
« Reply #90 on: January 19, 2024, 07:44:01 pm »
Eventually it will be released as 3.4.0, but the exact schedule for that is still unknown.

Is there a roadmap of fixes/features we're waiting on for 3.4?

Perhaps this will help:

https://wiki.freepascal.org/FPC_New_Features_Trunk

Revision history shows last change in June 2023.

This looks like a list of new features done waiting for 3.4 release to be included?

I'm looking for a list of things that need to be completed before the 3.4 release can be finished.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6396
  • Compiler Developer
Re: Feature announcement: Function References and Anonymous Functions
« Reply #91 on: January 21, 2024, 12:17:14 pm »
I'm looking for a list of things that need to be completed before the 3.4 release can be finished.

There is none. We'll start release preparation for 3.4.0 when we think we've reached a suitable point. This is currently not in sight and even then release preparation takes multiple months.

Okoba

  • Hero Member
  • *****
  • Posts: 660
Re: Feature announcement: Function References and Anonymous Functions
« Reply #92 on: February 02, 2024, 04:51:12 pm »
Hello,

This code in mode Delphi crashes, is it a bug? No problem on objfpc mode.
Tested on today Trunk.
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3.   {$mode Delphi}
  4.   {$modeswitch functionreferences}
  5.  
  6. type
  7.   TTest = reference to procedure(V: Integer);
  8.  
  9.   procedure Test1(V: Integer);
  10.   begin
  11.     WriteLn('Test1: ', V);
  12.   end;
  13.  
  14.   procedure Run;
  15.  
  16.     procedure Test2(V: Integer);
  17.     begin
  18.       WriteLn('Test2: ', V);
  19.     end;
  20.  
  21.   var
  22.     T: TTest;
  23.   begin
  24.     T := @Test2; //Error on Delphi mode but not objfpc
  25.     T(1);
  26.   end;
  27.  
  28. begin
  29.   Run;
  30.   ReadLn;
  31. end.                                  

Paolo

  • Hero Member
  • *****
  • Posts: 717
Re: Feature announcement: Function References and Anonymous Functions
« Reply #93 on: February 02, 2024, 05:12:20 pm »
What about removing "@" ?

Okoba

  • Hero Member
  • *****
  • Posts: 660
Re: Feature announcement: Function References and Anonymous Functions
« Reply #94 on: February 02, 2024, 06:17:20 pm »
That fixes the problem.
But why? As I remember even in Delphi mode, we use @ to address a function.
Is there a mode switch to activate using @ in Delphi mode?

dseligo

  • Hero Member
  • *****
  • Posts: 1686
Re: Feature announcement: Function References and Anonymous Functions
« Reply #95 on: February 03, 2024, 02:15:40 am »
That fixes the problem.
But why? As I remember even in Delphi mode, we use @ to address a function.
Is there a mode switch to activate using @ in Delphi mode?

You use @ to get address, but not to assign procedure or function.
See here (first one): https://www.freepascal.org/docs-html/prog/progse74.html

Okoba

  • Hero Member
  • *****
  • Posts: 660
Re: Feature announcement: Function References and Anonymous Functions
« Reply #96 on: February 03, 2024, 07:51:58 am »
So why compilers does not throw any error? If @ in Delphi mode is not accepted? It throws an error if I want to set a pointer of an integer to another one.

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. var
  4.   I, J: Integer;
  5. begin
  6.   I := @J;
  7. end.        

And on checking again without 'reference to' the variable, it is zero instead of the correct one, raising the question of why this time it accepts the procedure and even runs it, but with the wrong parameters?
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3.   {$mode Delphi}
  4.  
  5. type
  6.   TTest = procedure(V: Integer);
  7.  
  8.   procedure Test1(V: Integer);
  9.   begin
  10.     WriteLn('Test1: ', V);
  11.   end;
  12.  
  13.   procedure Run;
  14.  
  15.     procedure Test2(V: Integer);
  16.     begin
  17.       WriteLn('Test2: ', V);
  18.     end;
  19.  
  20.   var
  21.     T: TTest;
  22.   begin
  23.     T := @Test2;
  24.     T(1); //Writes 0
  25.   end;
  26.  
  27. begin
  28.   Run;
  29.   ReadLn;
  30. end.

Paolo

  • Hero Member
  • *****
  • Posts: 717
Re: Feature announcement: Function References and Anonymous Functions
« Reply #97 on: February 03, 2024, 03:48:12 pm »
I tested this code

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. //{$mode delphi}{$H+}
  4. {$mode objfpc}{$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     procedure Button1Click(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30. type
  31.  
  32.   TTest = procedure(V: Integer);
  33.  
  34.   procedure Test2(V: Integer);
  35.   begin
  36.     form1.caption:='Test2: '+V.tostring;
  37.   end;
  38.  
  39.   { TForm1 }
  40.  
  41.   procedure TForm1.Button1Click(Sender: TObject);
  42.   var
  43.     T: TTest;
  44.   begin
  45.     T := Test2;
  46.     T(3); //Writes 3
  47.   end;
  48.  
  49. end.
  50.  

it always works, just in objfpc mode without @ does not compile

PascalDragon

  • Hero Member
  • *****
  • Posts: 6396
  • Compiler Developer
Re: Feature announcement: Function References and Anonymous Functions
« Reply #98 on: February 04, 2024, 12:28:41 pm »
So why compilers does not throw any error? If @ in Delphi mode is not accepted?

Because nobody said that the compiler is flawless. And the function reference functionality is a complicated one... 🙄
Please report a bug.

Okoba

  • Hero Member
  • *****
  • Posts: 660
Re: Feature announcement: Function References and Anonymous Functions
« Reply #99 on: February 05, 2024, 05:00:08 pm »
Reported: 40626
@PascalDragon except this issue, I should say, Function reference works very well and easy, thank you!

deadserious

  • New Member
  • *
  • Posts: 25
Re: Feature announcement: Function References and Anonymous Functions
« Reply #100 on: February 06, 2024, 03:21:48 am »
We'll start release preparation for 3.4.0 when we think we've reached a suitable point.

What makes for a "suitable point"?

Thaddy

  • Hero Member
  • *****
  • Posts: 19243
  • Glad to be alive.
Re: Feature announcement: Function References and Anonymous Functions
« Reply #101 on: February 06, 2024, 06:31:36 am »
'when it is ready', as usual. release management is a lot of work.
- documentation ready
- test suites run without error
- new features completed or decided to postpone
- regressions fixed
- new platforms done
- packaging for all platforms done
- release notes written
and possibly more
objects are fine constructs. You can even initialize them with constructors.

beria2

  • New Member
  • *
  • Posts: 20
Re: Feature announcement: Function References and Anonymous Functions
« Reply #102 on: April 12, 2025, 10:30:09 pm »
'when it is ready', as usual. release management is a lot of work.
- documentation ready
- test suites run without error
- new features completed or decided to postpone
- regressions fixed
- new platforms done
- packaging for all platforms done
- release notes written
and possibly more

when will support for anonymous functions be added to objfpc? I'm tired of waiting because I don't see anything difficult about it.  :'( :'( :'( :'( :'( :'( :'(

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Feature announcement: Function References and Anonymous Functions
« Reply #103 on: April 12, 2025, 10:39:13 pm »
when will support for anonymous functions be added to objfpc? I'm tired of waiting because I don't see anything difficult about it.  :'( :'( :'( :'( :'( :'( :'(
Did you even read the announcement ? Available since may 2022 in trunk so no idea what you're waiting for tbh.
Today is tomorrow's yesterday.

beria2

  • New Member
  • *
  • Posts: 20
Re: Feature announcement: Function References and Anonymous Functions
« Reply #104 on: April 13, 2025, 12:00:20 am »
when will support for anonymous functions be added to objfpc? I'm tired of waiting because I don't see anything difficult about it.  :'( :'( :'( :'( :'( :'( :'(
Did you even read the announcement ? Available since may 2022 in trunk so no idea what you're waiting for tbh.

Free Pascal Compiler version 3.3.1-17783-gf672d4cccf-dirty [2025/04/10] for x86_64
-----------------------------
{$mode objfpc}
begin

    procedure(const aArg: String)
  begin
    Writeln(aArg);
  end('Hello World');

number.lpr(897,5) Error: Illegal expression

---------------
    {$MODE DELPHI}
       

begin

    procedure(const aArg: String)
  begin
    Writeln(aArg);
  end('Hello World');

Ok!
-------------------------------------
I still can't use them.... I'm probably very stupid and I don't understand something in principle. There are a lot of things in fpc that are unclear, which work, which don't, and so they work...

 

TinyPortal © 2005-2018