On Sun, 3 Sept 2023 at 10:48, Ivan Vorontsov <ivrntsv@yandex.ru> wrote: > With perl v5.38.0 I wrote a code similar to: > perl -E 'sub foo ($x, $y //= 42, $z) {} foo(1, undef, 3)' > and got the error: > Mandatory parameter follows optional parameter at -e line 1, near "$z) > " > > So //= and ||= mark a parameter as optional, but optional parameters must > follow mandatory ones. Outside of signatures these operators check a value > of a variable. A mandatory parameter can have undef or false value. If it > is feasible, maybe these operators could be applied to mandatory parameters > as well. > > you are mixing two domains not clearly formulated yet (in Perl) one is signatures, where operators acts like "if not exists" second is data contract, where you want "use 42 if undef" first one struggles with missing concept of "not-exists" value for second, you can use Type::Params for now, maybe current WIP (Oshun) will solve it in future > -- > Ivan Vorontsov <ivrntsv@yandex.ru> >Thread Previous | Thread Next