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

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

Thread Previous | Thread Next
From:
ASSI
Date:
September 5, 2023 17:02
Subject:
Re: //= and ||= in subroutine signatures
Message ID:
87wmx4h7tg.fsf@Rainer.invalid
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.


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

Factory and User Sound Singles for Waldorf rackAttack:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About