DIP 1019--Named Arguments Lite--Final Review

nkm1 t4nk074 at openmailbox.org
Wed Aug 28 09:37:13 UTC 2019


On Wednesday, 28 August 2019 at 09:00:08 UTC, Olivier FAURE wrote:
> With all that said, I still think the way Andrei asked "well 
> why didn't you just use Walter's version and ignore everything 
> else?" is a little presumptuous.

Well, it's not just because Walter proposed that. It's also 
because his proposal is the most obvious one. There is already 
designated initialization syntax for arrays and structs, so 
having something different for parameters to a function requires, 
at least, some justification. Espectially considering the fact 
that some programming languages don't have named parameters and 
instead use associative arrays literals (Perl, Lua).

sub sum_abc {
     my $abc = shift;
     return $abc->{a} + $abc->{b} + $abc->{c};
}

print sum_abc({ c => 3, a => 1, b => 2}), "\n";

D doesn't have struct literal syntax (yet?), but C does:

#include <stdio.h>

typedef struct { int a, b, c; } ABC;

int sum_abc(ABC abc) {
     return abc.a + abc.b + abc.c;
}

int main(void) {
     printf("%d\n", sum_abc((ABC) { .c = 3, .a = 1, .b = 2 }));
}

That looks pretty damn close to named parameters, doesn't it... 
And it's plausible that one day D will get struct literals 
(unless it got them while I wasn't looking?) Anyway, it 
absolutely must be discussed in the DIP (as "Prior Work"), and it 
doesn't matter whether it's Walter's proposal or anyone else's.


More information about the Digitalmars-d mailing list