develooper Front page | perl.perl5.porters | Postings from September 2023

Re: //= and ||= in subroutine signatures

Thread Previous | Thread Next
September 5, 2023 17:02
Re: //= and ||= in subroutine signatures
Message ID:
Dave Mitchell writes:
> 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

IMHO the only sensible interpretation of that syntax (given what it does
elsewhere) would have been "$y is a mandatory parameter that gets a
value of 1 (or whatever expression in that place) when passed an undef"
(and the same for "||=" when passed something that evaluates to
"false").  Optionality should have been strictly assigned by plain "=".
Of course think something like

$y //= "undef" = "default"

would have been subject to lengthy discussion, both on whether it should
even be there and what exactly it does.

+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf rackAttack:

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About