Likewise, I read
sub foo($x //= 1) {...}
as saying the value stored in $x is a constant, but if the caller passed an undefined value (or didn't pass anything at all), we're going to instead pretend they passed us a (still-constant) 1. I'm not sure why that violates any rules.(?)
//= means "assign to lvalue unless lvalue is defined". So I read that as:
$x is a constant variable. Bind the corresponding argument to $x and then assign 1 to it if its value is undef. But the container bound to $x is bound as a constant, so it *can't* be assigned to.
OK, I buy that, I think. But does that mean that fixing edge cases in your arguments doesn't work at all, i.e. you can't even do this?
sub foo(?$x) { $x //= 1; # if they passed an undef, init it to 1 ... }
or that you have to say it like this?
sub foo(?$x) { my $x = $x // 1; # hide $x param using a non-const C<my>? ... }
MikeL