Closed rktjmp closed 1 year ago
I think in particular this it makes case-try more "reason-able" where it will just error consistently whilst match-try might return nil or the unmatched value.
Can you elaborate on this? In my mind, this is maybe the best argument against case
erroring out. The point of the case-try
macro is to allow the failures to fall down to the catch
clause, and if there's a runtime error whenever a mismatch occurs, that's no longer possible.
I meant that case
could error if nothing matched, and case-try
could error if nothing matched in the catch
block -- and that it implicitly adds the (catch _ (error))
if needed. It would follow the "errors on no match" in spirit, but not a 1:1 implementation between case
and case-try
.
This was my reasoning, but I think its a flawed argument
After some thought, I think it's a bad idea because it forces all error handling inside the case-try, while it may be more appropriate to pass abnormal values up.
I think the most useful (if runtime-erroring) would be,
case
adds an implicit runtime _ (error ...)
final pattern.case-try
without catch
returns the unmatched value (needed so we can defer handling to caller, identical to match-try
without catch
)case-try
with catch
adds implicit runtime _ (error ...)
final pattern (to be "strict" like case).I think that leaves some ambiguity between what will raise "when you see the word case", but is correctly flexible.
Curious what your arguments for having a runtime error and having a compiler error are.
Hey, sorry but I think we've decided after discussing it in chat that this is probably too disruptive. Thanks for writing it out to help us talk thru the reasoning. =)
Speculative documentation if
case
was forced exhaustive.I think in particular this it makes
case-try
more "reason-able" where it will just error consistently whilstmatch-try
might return nil or the unmatched value.I generally did not add a
_ :otherwise
pattern to the examples as generally it seems out of scope (as in, previously returning nil might have exploded the theoretical program, so it's much the same?) but unsure if it makes them less helpful or not.There is an alternate idea floated where if you don't add a
_ x
clause the compiler yells at you, which is not documented here.Pro's I see for a compiler error:
Cons:
_ (error "unexpected item in the bagging area")
where the compiler could do this automatically?