Front page | perl.perl5.porters |
Postings from September 2023
Re: //= and ||= in subroutine signatures
Thread Previous
|
Thread Next
From:
Ivan Vorontsov
Date:
September 7, 2023 17:41
Subject:
Re: //= and ||= in subroutine signatures
Message ID:
20230907204100.2b848a51082a46024b60a489@yandex.ru
On Wed, 6 Sep 2023 00:37:13 +0300 Ivan Vorontsov <ivrntsv@yandex.ru> wrote:
> On Mon, 4 Sep 2023 14:10:56 +0100 Dave Mitchell <davem@iabyn.com> wrote:
>
> > On Sun, Sep 03, 2023 at 01:28:08PM +0300, Ivan Vorontsov wrote:
> > > Maybe genuine optional parameters must be only the ones marked by =
> > > sign. Others are mandatory. To mandatory parameters with //= or ||=
> > > operators, that are last in the list or precede optional ones with =,
> > > undef values are assigned, if there are less arguments than mandatory
> > > parameters, and then operator works with that value.
> >
> > I think that that's complex and confusing. You're basically saying
> >
> > f($x, $y = 1, $z = 2) # $y is optional parameter
> > f($x, $y //= 1, $z = 2) # $y is optional parameter
> > f($x, $y //= 1, $z ) # $y is mandatory parameter
> > f($x, $y //= 1 ) # $y is optional parameter
>
> With my suggestion it should be:
>
> f($x, $y = 1, $z = 2) # $y is optional parameter
> f($x, $y //= 1, $z = 2) # $y is mandatory parameter
> f($x, $y //= 1, $z ) # $y is mandatory parameter
> f($x, $y //= 1 ) # $y is mandatory parameter
>
> Consider this example:
>
> f($v, $w //= 42, $x, $y //= 1, $z = 2)
>
> Here $v, $w, $x, $y are mandatory, $z is optional. But function can be
> called with less arguments than number of mandatory parameters because
> of $y. In that case $y assigned undef, then checked assignment is
> applied. When number of arguments is equal to number of mandatory
> parameters only checked assignment is applied to $y. Checked assignment
> is applied to $w always.
>
> But with my suggestion = parameters must be very last in the parameter
> list without //= and ||= parameters in between them. That's a drawback.
> Right now they can be interspersed.
>
> > I think //= and ||= should be consistently either mandatory or optional,
> > and not vary based on context.
>
> Mandatory by the suggestion.
>
> > And since there already been a release (5.38) where they're optional, I
> > think we should keep it that way.
>
> As I understand unconditionally. So any change is a break. And a user
> visible break as far as I see is the prohibition of interspersing =
> parameters with //= and ||= parameters. Allowing interspersing
> mandatory parameters with //= and ||= parameters is an addition, not a
> break. It brings questions. Is the suggestion worthwhile the break? Is
> it implementable?
After some time I think that's not a good idea. Too much fuss for
too little. The current behavior is good enough for me. Thank you all
for attention.
--
Ivan Vorontsov <ivrntsv@yandex.ru>
Thread Previous
|
Thread Next