[fpc-pascal] Feature Announcement: Function References and Anonymous Functions

Thomas Kurz fpc.2021 at t-net.ruhr
Sat May 28 17:47:39 CEST 2022


This is horrendous code, especially the last example. Looks like PHP or JavaScript, which I hate because their code is hard to read. I'm using pascal because I like its clean and easy-to-read syntax.

"-1" is a statement that should give a compiler error. "Result" and "Exit(x)" are established constructs and I don't see any need for changing, or even worse: omitting, them.

What should the data type of "left, right" be?

What should "@" mean?



----- Original Message ----- 
From: Benito van der Zander via fpc-pascal <fpc-pascal at lists.freepascal.org>
To: fpc-pascal at lists.freepascal.org <fpc-pascal at lists.freepascal.org>
Sent: Saturday, May 28, 2022, 14:04:46
Subject: [fpc-pascal] Feature Announcement: Function References and Anonymous Functions

Hi,

> Sort((left, right) begin
>                      if left < right then
>                        result := -1
>                      else if left > right then
>                        result := 1
>                      else
>                        result := 0;
>                    end);

One could introduce the @ operator to get a reference to a block of code.

Sort( @(left, right) begin
                     if left < right then
                       result := -1
                     else if left > right then
                       result := 1
                     else
                       result := 0;
                   end);


The "result" variable is also ugly. You could make "if" an expression:

Sort( @(left, right) begin
                     result :=
                       if left < right then -1
                       else if left > right then 1
                       else 0;
                   end);


Then the begin end could be removed too. Make @:= an operator to turn an 
expression to a function

Sort( @(left, right) :=
                        if left < right then -1
                        else if left > right then 1
                        else 0;
                   );





Benito



More information about the fpc-pascal mailing list