[MATCH-36] throw on unsuccessful match Created: 27/Oct/11 Updated: 28/Jul/13 Resolved: 15/Jun/13
|Reporter:||David Nolen||Assignee:||David Nolen|
I was on the fence about this. But after looking at the literature as well as the behavior of condp, I've decided that throwing on unsuccessful match is the way to go. This is particularly important since we put no constraints on the types allowed - we cannot determine exhaustiveness.
|Comment by David Pollak [ 28/May/13 10:20 AM ]|
FWIW, I think the existing behavior (returning a nil) is the correct behavior. If a user wants to throw an exception, they can add an :else clause.
Why is the existing behavior correct?
Think of a Map as a match. When you look up a key that is not in the Map, you get a nil. There are simple ways to add additional behavior to maps to return something other than a nil, but the default is nil.
A Map, like a pattern match, is defined at some values of the input and not other values of the input.
|Comment by David Nolen [ 28/May/13 10:26 AM ]|
The behavior aligns with Clojure's case. The issue is that Clojure being dynamically typed (and match actively taking advantage of this) can't really do exhaustiveness checking in all cases - I think throwing is desirable, and experience seems to suggest this as well - otherwise nils will flow in likely unintentional ways. Users can always add the explicit nil return if they like. I suspect users will not do this.
|Comment by David Nolen [ 15/Jun/13 10:27 PM ]|