Case expression with Type argument and matches failes

Description

(defn f[x]
(case (class x)
Exception 1
String 2))

(f "asdf") => throws

(reported by Ramsey Nasser)

Environment

None

Activity

Show:
David Miller
April 2, 2018, 12:02 AM

Given that ClojureJVM and ClojureCLR agree on this, I prefer not to make a change.
perhaps a type-case construct?

Jeremy Sellars
March 3, 2017, 10:54 PM

This sounds like a feature request to Clojure (JVM) more than a defect in ClojureCLR.

  • Pros:

    • This would be convenient.

  • Cons:

    • For what it's worth, it doesn't look like Clojure (JVM) supports case switching on Class/Type (in 1.8, 1.9-alpah14). IllegalArgumentException No matching clause: class java.lang.String

    • My perception is that case is analogous to Java/C#'s switch which offers performance benefits over something like cond/condp by jumping to the right code. That benefit might be a trick to maintain for Type, given the opaque nature of .NET's hashing algorithm.

Declined

Assignee

David Miller

Reporter

David Miller