DIP 1020--Named Parameters--Community Review Round 2

rikki cattermole rikki at cattermole.co.nz
Thu Sep 12 18:21:50 UTC 2019

On 13/09/2019 6:00 AM, Yuxuan Shui wrote:
> On Thursday, 12 September 2019 at 14:36:09 UTC, rikki cattermole wrote:
>> On 13/09/2019 1:44 AM, Yuxuan Shui wrote:
>>> On Thursday, 12 September 2019 at 12:06:47 UTC, rikki cattermole wrote:
>>>> On 12/09/2019 11:50 PM, Yuxuan Shui wrote:
>>>>> On Thursday, 12 September 2019 at 11:46:46 UTC, rikki cattermole 
>>>>> wrote:
>>>>>> [...]
>>>>> Ah, sorry. I meant to write draw(shape: someShape).
>>>> In that case, two methods:
>>>> 1. void draw(Shape)(@named Shape shape) { draw(shape); }
>>>> 2. void draw(Shape:Circle)(@named Shape shape) { draw(shape); }
>>>> The second is better because of validating the parameter type, but 
>>>> does require one per type. Assuming I remember this particular bit 
>>>> of templates correctly.
>>>> I had to assume that drawing has to be specific to the type passed 
>>>> in and that the draw function will be concrete (can be virtual). But 
>>>> that shouldn't be a problem.
>>> Sorry, I don't think I understand your answer. My question has 
>>> nothing to do with templates.
>> To get the functionality you asked about, I had to use templates.
>> To support overloading on named parameters would require invasive 
>> changes and adding a new mangling sequence. Things I want to avoid.
>> a11e99z asked a similar question under your own in this part of the 
>> thread tree. Same answer.
> No, I am not asking for overloading based on name. The two functions are 
> clearly distinct based purely on parameter types.
> I think this basically means you cannot create functions with only 
> @named parameters. I consider this a pretty serious limitation.

You can create functions with just @named parameters, but you can't use 
overloading with them.

Its a side effect of not touching symbol+overload resolution.

Keep in mind that the syntax:

void draw(Shape:Circle)(@named Shape shape)

will allow you to have multiple functions named the same thing with 
@named parameters. So its not as serious as it may first seem IMO.

More information about the Digitalmars-d mailing list