As a new developer to Clojure, coming from a strong Java/OO background
and NOT a functional one, I'd like to make a few observations.
One challenge to new developers are exception messages generated by
Clojure. I'm seeing a lot of ClassCastExceptions:
cribbage=> (sort-by card-order (take 11 deck))
java.lang.RuntimeException: java.lang.RuntimeException:
java.lang.ClassCastException: clojure.lang.Keyword (NO_SOURCE_FILE:0)
cribbage=> (.printStackTrace *e)
java.lang.ClassCastException: clojure.lang.LazyCons (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:4122)
at clojure.lang.Repl.main(Repl.java:91)
Caused by: java.lang.ClassCastException: clojure.lang.LazyCons
at clojure.nth__461.invoke(boot.clj:844)
at cribbage.eval__3056.invoke(Unknown Source)
at clojure.lang.Compiler.eval(Compiler.java:4111)
... 1 more
nil
cribbage=>
That's not a lot to go on; my eventual error was here:
(def face-card-order {:jack 11 :queen 12 :kind 13})
(defn card-order
"Returns the sort ordering of the card, which is the rank, extended
with values for :jack, :queen
and :king."
[{rank :rank}]
(or (face-card-order rank) rank))
(defn card-value
"Returns point value of card, which ranges from 1 to 10 (for 10
and all face cards)."
[{rank :rank}]
(if (contains? face-card-order rank) 10 rank))
:king vs. :kind inside face-card-order, thus :king was returned (not
10) which cases a comparison error.
The point is, an exception that said something like:
"Expected java.lang.Comparable but received :king" would have helped
me unravel this much, much easier!
I have a lot of experience, inside Tapestry, on these kinds of issues:
useful exception reporting. A significant amount of Tapestry's code
base revolves around exception reporting, as does a
more-than-signficant amount of the test cases.
At the very least, I'd like to see a diagnostic with every
ClassCastException, identifying what was being cast (and perhaps why)
along with the expected type.
--
Howard M. Lewis Ship
Creator Apache Tapestry and Apache HiveMind
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---