On 26.12.2021 17:40, Ryan Joseph via fpc-devel wrote:
I'm 99% certain using the method name "Invoke" would be rejected on the grounds
of backwards compatibility.
Not to argue for the "procedure/function Invoke" syntax, but it hardly breaks backward
compatibility. Only in the purest non-practical sense: "I maintain this code that always used
to be rejected and suddenly it gets compiled".
Adding a new syntax using "default" like "function Add9(const N: Integer): Integer;
default;"
That is pretty much the /old/ syntax.
I agree with Michael that it would mirror default properties nicely, but:
1) Are we most likely to name that "default method" or "call operator"?
2) We now have proper operator overloading; I would even argue that, were it added to
Object Pascal much earlier, we would have had "operator Index" instead of
default array properties;
3) I would rather reserve the DEFAULT directive on methods for default
interface methods:
-------8<-------
type I = interface
procedure Foo; default;
// the above, IMO, looks better than
// procedure Foo; not abstract;
end;
procedure I.Foo; begin { default implementation } end;
-------8<-------
class operator Call(....);
Again, the proposal is:
-------8<-------
type R = record
operator Invoke(...)...;
end;
-------8<-------
Specifically:
A) without CLASS:
1) Having to declare Self manually would be ridiculous;
2) In interfaces, that method should be instance-virtual.
B) The name Invoke is required for compatibility with DCC.
Granted, for "operator", some hackery would still be required for 100% DCC
compatibility:
-------8<-------
type MethRef = reference to procedure;
type C = class(TInterfacedObject, MethRef)
// This needs to map to _operator_ MethRef.Invoke
procedure Invoke;
end;
-------8<-------
it doesn't present any new syntax
So, in your book, introducing a /new/ operator identifier "doesn't present any new syntax" (and I
agree), but semantically allowing the /existing/ directive DEFAULT to appear in the existing list of method
directives is somehow "a new syntax". You have some interesting definition of "syntax".
--
βþ
_______________________________________________
fpc-devel maillist - [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel