Quick actions

cmd+k|ctrl+k

Navigation

Languages

Untitled

Snippet info

Language

Raku

Visibility

unlisted

Author

legacy-anonymous

Created

2026-01-05T21:25:45.348906Z

Updated

2026-01-05T21:25:45.348906Z

use nqp;

# for proper R5RS semantics, run this once wrapping your main function
sub run_main($f) {
    nqp::continuationreset(nqp::null(), $f);
}

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) });
    });
}

run_main {
  say "hello";
}
INFO