> On May 28, 2022, at 7:04 PM, Benito van der Zander via fpc-pascal
> <[email protected]> wrote:
>
> 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);
Swift, C# and JavaScript etc… allow you to omit the return statement if the
function body is a single expression. I don’t think any languages I’m aware of
break the rules of expression though like this is proposing but you could use
exit() and it would look a little better.
>
>
>
> 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 don’t think you need the @ operator here since the ():= is enough to denote a
function. This is like the “arrow” syntax in JavaScript and it makes sense to
me. It’s a good idea I think.
Come to think of it is FPC going to support capture lists? Right now the entire
scope is captured but this is not always ideal. Right now there’s no syntax
currently available that would support that.
Regards,
Ryan Joseph
_______________________________________________
fpc-pascal maillist - [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal