Discouraging The Interception of Divergent Panics

I feel like I should mention that there is a trick that could get you the error or the value if there was no error, without using ENRECOVER...

The RECOVER operation could convert an abrupt failure into a definitional one. Then you could use EXCEPT to handle the error case, while getting your value out the top of the expression in the non-abrupt-failure case:

result: sys.util/recover [
    if condition [panic "This is a divergent panic"]
    10 + 20
] except e -> [
    ; handle the divergent panic
]

For a construct named RECOVER, it doesn't seem to make sense.

  • recover [...] then x -> [...] naturally implies "this is code I want you to run if you recovered something, pass me the error you caught in a defused way."

  • recover...except makes it sound like the recovery didn't succeed.

Considering that you're not really supposed to be using SYS.UTIL/RECOVER hardly ever, it doesn't seem like too much of a burden to just move your assignment inside the body:

sys.util/recover [
    if condition [panic "This is a divergent panic"]
    result: 10 + 20
] then e -> [
    ; handle the divergent panic
]

But Maybe It Just Needs Another Name?

Multiplexing the intercepted divergent error onto the body result might make more sense if it were called something like SANDBOX:

result: sys.util/sandbox [
    if condition [panic "This is a divergent panic"]
    10 + 20
] except e -> [
    ; handle the divergent panic
]

Though that sounds like a noun more than a verb. ISOLATE... though that sounds more like a context thing, for isolating variables. QUARANTINE, I dunno.

:thinking:

Getting rid of ENRECOVER seems desirable, and the more natural form of multiplexing is to use ERROR! itself with the body return value, not this weird lifting idea.

Another aspect that makes me open to a new name and interface is that RECOVER and RESCUE are two rather similar words that start with R. This would help eliminate confusion between a construct that picks out definitional errors from sequential steps in an expression vs. one that does the dangerous deed of intercepting divergent errors.