Discussion Thread: DIP 1030--Named Arguments--Final Review
Paul Backus
snarwin at gmail.com
Thu May 21 01:07:36 UTC 2020
On Wednesday, 20 May 2020 at 20:01:51 UTC, Arine wrote:
> On Wednesday, 20 May 2020 at 03:04:13 UTC, 12345swordy wrote:
>>
>> So if the implementation detail is standardized, would you
>> still object to this?
>>
>> -Alex
>
> Both methods are terrible. A pull request that used either
> method in phobos would be rightfully rejected today. It doesn't
> bode well when such a destructive practice is suggested by the
> creator of a language, and then they completely fall silent
> from the discussion. I hope he doesn't have have the same
> holier than though mindset as that other individual that
> clearly stated they don't care about having any kind of
> discussion on the subject at all. That's fine by me, it's clear
> as night and day to me. Practicality seems to be going out the
> door lately anyways.
Here's a method that works using existing language features and
doesn't rely on implementation details that aren't part of the
language spec:
int foo(int, int)
{
static if (is(typeof(__traits(parent, {})) params ==
__parameters)) {
mixin("alias x = ", __traits(identifier, params[0..1]),
";");
mixin("alias y = ", __traits(identifier, params[1..2]),
";");
}
return x + y;
}
unittest
{
assert(foo(1, 2) == 3);
}
It's pretty ugly, but the ugliness is hidden entirely inside the
function's implementation. And the whole static if block could be
factored out into a mixin if you wanted to re-use it in multiple
functions.
More information about the Digitalmars-d
mailing list