On Thu, 29 Jun 2017 00:45:02 -0700, elizabeth wrote:
> Shouldn’t:
> 
> sub ($ is rw) { }
> 
> be a compile-time error?  I mean, there is no way to actually assign
> to the anonymous variable, is there?  So there is no point in the “is
> rw”.  So most likely indicates a typo on the user side.
> 

Feels a bit of an overreach to make that judgement. What if I don't want to 
assign anything to it, but just want to force the user of my sub to use a 
writable container? There might be a usecase for wanting that. While typoing a 
variable name would be easily detected via another error, when the user tries 
to use the variable in the body.

For example, I can multi-dispatch based on that and it works right:

    <Zoffix__> m: multi foo ($) { say 'here' }; multi foo ($ is rw) { say 
'there' }; foo 42
    <camelia> rakudo-moar 2a8d1e: OUTPUT: «here␤»
    <Zoffix__> m: multi foo ($) { say 'here' }; multi foo ($ is rw) { say 
'there' }; foo $ = 42
    <camelia> rakudo-moar 2a8d1e: OUTPUT: «there␤»

Or I want to unpack only iterables with writable containers, while grabbing all 
but one item, which actually seems to have another bug in it in that the anon 
doesn't force rw at all:

    <Zoffix__> m: sub foo (@ ($x is rw, |c)) { say c }; foo (42, 42)
    <camelia> rakudo-moar 2a8d1e: OUTPUT: «Parameter '$x' expected a writable 
container, but got Int value␤  in sub foo at <tmp> line 1␤  in block <unit> at 
<tmp> line 1␤␤»
    <Zoffix__> m: sub foo (@ ($ is rw, |c)) { say c }; foo (42, 42)
    <camelia> rakudo-moar 2a8d1e: OUTPUT: «\(42)␤»

Reply via email to