Dave, now that you've explained this, your proposal does seem by far the simplest and backwards compatible option for named parameters, versus "real" named parameters that I mentioned. -- Darren Duncan On 2022-01-31 12:50 p.m., Dave Mitchell wrote: > On Fri, Jan 21, 2022 at 09:38:41PM -0800, Darren Duncan wrote: >> I know this isn't the main point of what you're saying, but I want to >> address the matter of named arguments. >> >> Your example code using "=>" may have just been representative and not literal. >> >> But I want to argue that when/if Perl does add native support for named >> parameters/arguments, which I hope it does, I feel that we must use a NEW >> syntax to indicate it, and NOT use "=>". > > > Just to be clear here. I fully expect that function calls will always > consist of the caller passing a list to the function, and that the > proposed named parameter syntax is just a way of easily processing > adjacent pairs of values in that list. So in: > > sub foo(:$x, :$y) { ... } > > The caller is expected to pass 4 arguments. How the caller does this is up > to the caller. They could do > > foo('x', 1, 'y', '2'); > @args = qw(y 2 x 1); foo(@args); > foo(y => 2, x => 1); > > or even (as I suggest in a separate proposal) > > foo(=$x, =$y) > > where '=$VARNAME' is syntactic sugar for > > ('VARNAME', $VARNAME) > > and indeed can be used anywhere, not just in argument lists: > > @point = (=$x, =$y); # short for ('x', $x, 'y', $y); > > If anyone expects sub foo(:$x, :$y) {} to be anything other than the > approximate equivalent of the following, please explain how you would make > it differ. > > sub foo { > croak unless @_ == 4; # actually a bit more subtle than that > for (0,2) { > croak unless $_[$_] =~ /^(x|y)$/; > } > my %args = @_; > my ($x, $y) = @args{'x', 'y'}; > } > > and in particular whether named args can be called with non-name caller > syntax, to allow modules to upgrade to signatures without affecting > callers. > >Thread Previous | Thread Next