Quick actions

cmd+k|ctrl+k

Navigation

Languages

Untitled

Snippet info

Language

Raku

Visibility

unlisted

Author

legacy-anonymous

Created

2026-01-05T21:40:29.19309Z

Updated

2026-01-05T21:40:29.19309Z

use nqp;

# for proper R5RS semantics, run this once wrapping your main function
sub run_main($f) {
    nqp::continuationreset(nqp::null(), nqp::getattr($f<>, Code, Q[$!do]));
}

sub callcc($f) {
    # first get the current continuation
    nqp::continuationcontrol(1, nqp::null(), -> $dcont {
        my $scheme_cont := -> $val {
            # when the scheme continuation is invoked, we need to *replace*
            # the current continuation with this one
            nqp::continuationcontrol(1, nqp::null(), -> $c {
                nqp::continuationinvoke($dcont, { $val })
            });
        };
        nqp::continuationinvoke($dcont, { $f($scheme_cont) });
    });
}

callcc -> &f {
    for ^20 {
        if $_ == 15 {
            f();
        }
    }
}
INFO