Michael Lazzaro wrote:

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
       ...
   }

That's right. It's an error. You need:


     sub foo(?$x is copy) {
         $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>?
       ...
   }

That won't work either, since the name of the lexical variable C<$x> is introduced immediately in Perl 6, so the C<$x> on the lhs is the lexical one from the rhs, not the parameter.


Damian




Reply via email to