On Tuesday, March 25, 2003, at 02:19 PM, Damian Conway wrote:
And I don't think that allowing 20 different types of assignment in the parameter list of a subroutine actually helps at all. Especially since the vast majority of parameters in Perl 6 will be constant.

Twenty types of _initialization_. :-D


Seriously, tho, I'm not sure I understand the constantness part.

sub foo($x = 1) {...} # A6 syntax

I read the above as saying $x is indeed constant, but if it's not explicitly placed by the caller, we're going to pretend the caller passed us a 1. 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.(?)

As a marginal bonus, perhaps an assertion-style

sub foo($x //= 1) {...}

optimizes to be faster, runtime, than

sub foo($x) { $x //= 1; ... }

when passing a constant in $x, e.g C<foo(5)> or C<foo('BLAH')>, since it can optimize out the assertion at compile-time?

MikeL

Reply via email to