Discussion Thread: DIP 1030--Named Arguments--Final Review
Jonathan Marler
johnnymarler at gmail.com
Wed May 13 19:44:32 UTC 2020
On Wednesday, 13 May 2020 at 19:31:24 UTC, Steven Schveighoffer
wrote:
> On 5/13/20 3:30 PM, Walter Bright wrote:
>> On 5/13/2020 12:55 AM, 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.
>>
>> In D, we do:
>>
>> void copy(string, string destination);
>
> And how does the implementation of copy use that first
> parameter?
>
> -Steve
I found a way:
void copy(string, string destination)
{
alias source = _param_0;
}
I didn't realize you could do this till now but this allows
functions to "opt-out" of using named parameters. We may want to
consider using this pattern throughout phobos/druntime when we
want want to prevent parameter names from being apart of the API.
More information about the Digitalmars-d
mailing list