Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CONTROL or once messes with last?

Tags:

exception

raku

This loop never stops:

class CX::Vaya does X::Control {
    has $.message
}

loop {
    once {
        CX::Vaya.new( message => "I messed up!" ).throw;
    }
    last;
    CONTROL {
        default {
            say "Controlled { .^name }: { .message }"
        }
    }
}

It keeps writing

Controlled CX::Last: <last control exception>
Controlled CX::Last: <last control exception>
Controlled CX::Last: <last control exception>
Controlled CX::Last: <last control exception>
Controlled CX::Last: <last control exception>
Controlled CX::Last: <last control exception>
Controlled CX::Last: <last control exception>
Controlled CX::Last: <last control exception>
...

It could be the once bit, because CONTROL phaser with last does finish:

loop { say "Hey"; last; CONTROL { default: .message.say } }
# OUTPUT: «Hey␤<last control exception>␤»

But I'm not really sure.

like image 257
jjmerelo Avatar asked Jun 27 '19 05:06

jjmerelo


People also ask

What mess removes mold?

To eradicate the mold you must destroy 6 green, glowing, mold balls. You can destroy these mold balls by either using your Service Weapon or by launching an object at them. Keep an eye out for any Hiss forces too.

How do you remove mold?

Use undiluted white vinegar on hard surfaces in kitchens and baths. A bleach solution also works to kill mold. Mix one cup of bleach in a gallon of water, apply to the surface and don't rinse. Mix a 50/50 solution of ammonia and water.

Where is the Furnace control game?

The Furnace is a paranatural entity found in the Furnace Chamber in the Maintenance Sector.


1 Answers

Loop flow control in Perl 6 is implemented using control exceptions. Thus, last is actually throwing a CX::Last control exception. Since the CONTROL block uses default, it is therefore catching the CX::Last thrown by last, meaning that control is never transferred out of the loop.

The fix is to instead specify which control exception to catch, using when:

loop {
    once {
        CX::Vaya.new( message => "I messed up!" ).throw;
    }
    last;
    CONTROL {
        when CX::Vaya {
            say "Controlled { .^name }: { .message }"
        }
    }
}
like image 70
Jonathan Worthington Avatar answered Jan 03 '23 16:01

Jonathan Worthington