Skip to content
Bill Hails edited this page Dec 7, 2023 · 12 revisions

The special construct here takes a function of one argument and passes it the current continuation as a function so that calling the current continuation is equivalent to returning through here. An example may make this clearer (or might not, continuations are notoriously tricky to get your head around at first 😁)

fn test(k) { k(3) }

3 + here fn(k) {
    if (test(k)) {
        4
    } else {
        5
    }
};

returns 6.

A continuation is first class like any other function and can be passed to other functions, stored in variables, called later etc. Simply put, continuations are first-class return statements.

The type of here is ((#a -> #b) -> #a) -> #a.

here is called call-with-current-continuation, or call/cc in other languages.

Clone this wiki locally