3 ms·
'Toss' sounds like an interesting language construct: it walks the stack to find an exception handler and then walks back to where it was to resume execution as
by kgeist 2y ago
'Toss' sounds like an interesting language construct: it walks the stack to find an exception handler and then walks back to where it was to resume execution as if nothing happened. It looks like you can inject additional behavior at runtime using this construct. Usually in object-oriented code you do dependency injection using services's constructors, but 'toss' allows to do it using "toss handlers"?
- bradrn 2y agoThis is quite similar to the Common Lisp conditions system… which I actually don’t know much about, but I do know that it lets you inject behaviour at runtime like this does.
- masklinn 2y agoIt's a very restricted form of conditions, since it only allows resuming. A conditions system would subsume both `toss` and `hurl` (because you can have an unwinding restart), as well as provide more flexibility: the condition can provide multiple user-defined restarts and the handler can pick between them (statically or dynamically), as well as feed content back into the signalling function. For instance a classic CL restart is `use-value` which is the conventional name of restarts feeding a default value in case of missing or invalid item. So let's say that you have a hashmap type, on lookup failure it could trigger a condition with a `use-value` handler to feed it a default value (possibly dynamically constructed), or abort/unwind, it could also have a restart to insert-and-return the value (so would behave as a `defaultdict`/`putIfAbsent`)
- mjbrusso 2y agoThis is similar `Resume Next` in VB
- tylerhou 2y agoCheck out Koka, a “legit” language with an algebraic effect system. https://koka-lang.github.io/koka/doc/book.html#why-handlers https://koka-lang.github.io/koka/doc/book.html#why-handlers