On 2010-Feb-22, at 2:08 am, Moritz Lenz wrote:
At least I'd find it more intuitive if smart-matching against Bool would coerce the the LHS to Bool and then do a comparison, much like smart-matching against strings and numbers work.

The downside is that then: given $thing { when some_function($_) {...} } won't work as intuitively expected if $thing is false and some_function
returns True.


The problem is the same construct is trying to do two different things. I agree that Any ~~ Bool should compare both sides as bool, because that's more consistent, and there should be another way to ignore the LHS.

I propose "whenever": it suggests that any time whatsoever that the RHS is true, the block will be executed. It's like "when", because it is related, but it also has the hand-waving, dismissive feeling of "whatever", as in, "Given $foo? Whatever!! I'm ignoring that and looking only at this particular value now!"


  say "Q: $question (Y/N)?";
  my Bool $answer = %answers{$question};
  my Bool $guess = get-response;

  given $guess
  {
      whenever now() > $limit  { say "Time's up!" }
      when $answer  { say "That is correct!" }
      default  { say "Sorry, wrong answer" }
  }



-David

Reply via email to