class Condition does X::Control {}
constant status = $ = 0;
constant things-to-do =
{ put 'showing status is ', status }, # Behavior 1: show status
{ put 'throwing condition'; Condition.new.throw } # Behavior 2: raise condition
loop { print 'doing something; '; things-to-do.pick.() } # Randomly pick numbered behavior
constant restarts =
{ put 'changing status to ', ++status }, # Restart 1: increment status and...
{ put 'changing status to ', --status }, # Restart 2: decrement status and...
{ die 'time to die!' } # Restart 3: end program
CONTROL {
when Condition # Catch condition
{ print 'restarting; '; restarts.pick.(); .resume } # Randomly pick numbered restart
default { .resume } # Default to just restarting
}