<< Back to previous view

[MATCH-36] throw on unsuccessful match Created: 27/Oct/11  Updated: 28/Jul/13  Resolved: 15/Jun/13

Status: Closed
Project: core.match
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Critical
Reporter: David Nolen Assignee: David Nolen
Resolution: Completed Votes: 1
Labels: None


 Description   

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.



 Comments   
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 ]

fixed, http://github.com/clojure/core.match/commit/63e56f524e60644460a9e43e1312966c42c3a5d5

Generated at Sun Dec 21 16:23:10 CST 2014 using JIRA 4.4#649-r158309.