Trey Harris wrote: > markstos++ pointed out the following behavior: > > use v6-alpha; > > { > when 1 ~~ 0 { > say "Surprise!" > } > } > > This code prints "Surprise!", because $_ is undef, which is false, just > like 1 ~~ 0 is. > > I'd like to make the following suggestions for Synopsis clarification: > > 1. It will be a very common pitfall, I think, to write C<when> as a > synonym for C<if>. For an extra layer of safety for such a novitiate > mistake, a boolean used as an argument to when should emit a warning > unless suppressed with an explicit C<?()>. > > when 1 ~~ 0 # warning > when ?(1 ~~ 0) # no warning > > 2. I think C<when> should either be disallowed outside of C<given>, or > it should be made to do something useful.
To refine this point a bit, the spec is clear that 'when' is useful not just with 'given' but with "any block that sets $_". I agree that it should be an error outside of "any block that sets $_", and I ask that that "any block that sets $_" be further defined. "for" statements and method bodies are mentioned explicitly, but it would be nice to have something approach a complete list. Mark