← Back to context

Comment by int_19h

1 month ago

`Result` is clearer given that in Pascal, a function name by itself in any other context is a function invocation (with no arguments). That is, you then have this kind of stuff:

  type PInteger = ^Integer;
  var X: Integer;

  function Foo: PInteger;
  begin
    Foo := @X;
    Foo^ := 123;
  end; 

The first assignment here is assigning to the magic result variable, while the second one recursively invokes the function and dereferences the returned pointer to assign through it. This is technically not ambiguous (since you can never have a naked function call on the left side of the assignment, unlike say C++), but it's a subtle enough distinction for human readers. No such problem with `Result`, obviously, which is presumably why it was one of the things that Delphi added since day 1.