On Wed, Feb 27, 2002 at 10:32:24AM -0600, Garrett Goebel wrote: > > Why does C<when>'s EXPR pay attention to the topicalizer regardless of > associated variable? > > Why introduce the special case? Especially when consistency and > simplification seem to be a strong undercurrent in Perl6? I'm curious what > the reasoning behind the special case is. I don't see what it gives us... > beside one more thing to remember. What would be a use case that illustrates > the need for the special case? And is the special case the common one? > > $_ = 'foo'; > given 'bar' -> $f { > if /foo/ {print}; # true, prints 'foo' > when /bar/ {print}; # true, prints 'foo' > when /bar/ -> $g {print}; # true, prints what? 'foo' > }
Why? Because it's oh-so dwim. Think about it, if you've just typed a given $x { ... or given $x -> $y { ... you know for a fact that you're going to want every C<when> to compare against the $_ or $y. Why force people to type: when $y =~ /a/ {...} when $y =~ /b/ {...} ... when you already know what they mean? And yes, it's the common case. How many times do you think you'll have a switch statement and want the case to compare against some value external to the switch? $_ = 'foo'; given 'bar' -> $y { when /a/ {...} } It's counterintuitive for this to translate to "When that foo value matches /a/ then take an action." If you'd meant that, it would make alot more sense to do: given 'foo' { when /a/ {...} } Allison