3 ms·
The most interesting part of this article for me is at the beginning. > Now imagine that calls could specify alternate return points, letting the callee decide
by mmaniac 2y ago
The most interesting part of this article for me is at the beginning.
> Now imagine that calls could specify alternate return points, letting the callee decide the statement to return to:
// Dreamed-up syntax
fn f() {
g() alternate |x| {
dbg!(x); // x = 123
};
}
fn g() -> () alternate i32 {
return_alternate 123;
}
This sort of nonlocal control flow immediately calls to mind an implementation in terms of continuation passing style, where the return point is given as a function which is tail called. Nonlocal returns and multiple returns are easy to implement in this style.
Does there exist a language where some function
fn foo() -> T throws U
is syntactic sugar for something more like?
fn foo(ifOk: fn(T) -> !, ifExcept: fn(U) -> !) -> !
- gpderetta 2y agoscheme I guess?
- compressedgas 2y agoSee Multi-return Function Call by Olin Shivers and David Fisher https://www.khoury.northeastern.edu/home/shivers/papers/mrlc.pdf https://www.khoury.northeastern.edu/home/shivers/papers/mrlc...