Patrick R. Michaud wrote:
> On Sun, Sep 21, 2008 at 07:02:37PM -0700, Michael G Schwern wrote:
>> I'm pondering what the proper syntax is for a subroutine parameter with both
>> a
>> trait and a default. That is...
>> sub foo ($arg = 42)
>> and
>> sub foo ($arg is readonly)
>> together in one parameter. Would that be
>> sub foo ($arg = 42 is readonly)
>> or
>> sub foo ($arg is readonly = 42)
>>
>> The first looks ambiguous, what if the trait is meant to apply to the
>> default?
>> The second looks downright wrong.
>
>
> The STD.pm grammar [1] shows that the second is the correct form --
> i.e., default values occur after traits. (See "token parameter"
> on or about line 2630.) I think part of the reason for this is that
> traits appearing after the default value would be applied to the
> default value instead of the parameter. A few other examples from
> the synopses seem to confirm this pattern:
>
> S03:2289: my Dog $fido is trained is vicious = 1
> S03:3828: constant Dog $foo is woof = 123;
> S06:1558: constant $pi is approximated = 3;
> S12:1393: has SomeType $.prop is rw = 1;
>
> 1. http://svn.pugscode.org/pugs/src/perl6/STD.pm
Ok, thanks. That does make sense.
>> PS Incidentally, it seems silly to have "is rw" but not "is ro". I keep
>> writing "is ro".
>
> Yes, we've also run into this problem a few times while working on Rakudo.
I'm finding it so verbose that I'm going with "is ro" in Method::Signatures.
--
I'm pale as formica, social skills stunted small. But I'm accurate
like a pica, I know the capital of nepal. I'm the nemesis of error,
dreadful diction fears my skills, more inquisitive than Jim Lehrer,
snottier than Beverly Hills.
-- I.L.O.P. Secret Rap http://goats.com/archive/020830.html