Am 28.05.2022 um 14:04 schrieb Benito van der Zander via fpc-pascal:
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 sequence "@(identifier" is already a valid sequence (because
"@(SomeVar)" is valid) and I'm definitely and absolutely against
introducing another ambigous syntax as I already have enough headaches
with Delphi's generic syntax.
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);
Allowing if (and case) to be an expression, too, is something I'm still
toying with independantly of this...
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;
);
I personally would have a bit more verbose syntax though it would have
the same problem regarding type inference which would be an absolute
PITA to implement (not to mention the opposition from the other core devs):
=== code begin ===
Sort(lamba (left, right) as
if left < right then -1
else if left > right then 1
else 0);
=== code end ===
Regards,
Sven
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal