Discussion Thread: DIP 1030--Named Arguments--Final Review
Paul Backus
snarwin at gmail.com
Wed May 13 13:15:20 UTC 2020
On Wednesday, 13 May 2020 at 07:55:33 UTC, Jacob Carlborg wrote:
> Regarding renaming parameters will break the API. Swift
> supports giving a different name which are used locally:
>
> func copy(_ source: String, to destination: String)
>
> Should be called like this:
>
> copy("foo", to: "bar")
>
> `_` indicates that the argument can not be named when calling
> the function. `to` is the name that is used when calling the
> function. `source` and `destination` are the names used locally
> in the implementation of the function.
>
> This allows to rename a parameter (the local name) without
> breaking the API.
Worth noting that this can also be done in D using local alias
declarations:
void copy(const(char)[] _, char[] to) {
alias source = _;
alias destination = to;
// etc.
}
Granted, the D compiler will not actually stop anyone from giving
the first argument by name, but it's hard to imagine why anyone
would want to.
More information about the Digitalmars-d
mailing list