At 05:51 PM 04-16-2002 +0100, Piers Cawley wrote: >Also known as constructs you wish you hadn't discovered. > >So, I'm reading through Finkel and I came across the following, which >computes the greatest common divisor of a and b (recast into perl6ish >syntax) > > while { > when $a < $b { $b -= $a } > when $b < $a { $a -= $b } > } > >The idea is that the loop keeps on looping until none of the guard >conditions match.
I believe that it also has exactly one guarded clause executed per loop, no matter how many guard conditions are true. So the following would be legal: while { when $a < $b {$b -= $a; print "First clause\n"; } when $b < $c {$c -= $b; print "Second clause\n"; } when $c < $a {$a -= $c; print "Third clause\n"; } } and if it started with ($a,$b,$c) = (3, 18, 24) there is no guarantee what order it would print in, but it would stop when ($a, $b, $c) == (3,3,3). >So, do we want this monstrosity? I confess that I did find myself >using something like it occasionally when I was working on the scheme >evaluator, but it looks very weird indeed. It's weirder when you allow multiple guard conditions to be true with no guarantee of evaluation order. But I see no reason to disallow it.