On Wed, Mar 12, 2003 at 12:18:33PM +1100, Damian Conway wrote:
> Various folks have suggested that the default assignment syntax:
>
> sub foo(?$bar is copy = 1) {...}
>
> be considered merely a shorthand for something like:
>
> sub foo(?$bar is copy is default(1)) {...}
>
> thereby allowing:
>
> sub foo(?$bar is default(1) is copy ) {...}
>
> and hence (mirabile dictu):
>
> sub foo(?$bar = 1 is copy ) {...}
>
>
> The design team has already considered this idea, and my problem
> with it then (and now) is that it's inconsistent with other forms
> of variable declaration:
>
> my sub foo( ?$bar is constant = 1 ) {...} # OKAY
> my $bar is constant = 1; # OKAY
>
> my sub foo( ?$bar = 1 is constant ) {...} # OKAY
> my $bar = 1 is constant; # KABOOM!
>
> and thereby lays a cognitive trap for programmers.
Does it work if the = shorthand is only allowed at the rightmost end of
the specification.
ie
my sub foo( ?$bar = 1 is constant ) {...}
is also defined to be a "KABOOM!" ?
Hence you're allowed to write "is default(42)" as "= 42" only if it's the
last trait. (Is that the right word)
But this feels bad because it's a special case. And an ordering related
special case, which seems to feel more bad to me.
Nicholas Clark