6 ms·
I don't know if this is just their test runner or whether it is a problem in Clojure proper, but it's really frustrating to see "Assertion failed" with zero des
by sirclueless 14y ago
I don't know if this is just their test runner or whether it is a problem in Clojure proper, but it's really frustrating to see "Assertion failed" with zero description of the runtime error. I have to fire up a REPL and reverse engineer the expected value, instead of just observing what the expression evaluates to as in the ruby koans.
As an example:
"But watch out if you try to pop nothing"
(= __ (try
(pop '())
(catch IllegalStateException e "No dice!")))
That code causes an error that looks like this:
Problem in /home/clueless/clojure-koans/src/koans/02_lists.clj
---------------------
Assertion failed!
But watch out if you try to pop nothing
(= __ (try (pop (quote ())) (catch IllegalStateException e "No dice!")))
That's just a transliteration of the Clojure expression from my source code. It's not even as good as a line number, because it's not greppable. If I were actually to encounter this in a failing test, you had better believe I would want to know what the right-hand-side actually evaluated to in context, not just what the compiled expression looks like.
- martinced 14y agoThis is some kind of a sad example you put here on HN... This is basically the worst part of Clojure (and only on the JVM at that): catching a Java exception. I know that's not your point but --and I'm a huge Clojure fan-- seeing a Java idiosynchrasy like that one makes me want to give up Clojure : (
- sirclueless 14y agoIn this case it's a Java wart, yes, but the same thing happens with other parts of the language. Another example: "Conjoining an element to a list can be done in the reverse order" (= __ (conj '(:a :b :c :d :e) 0)) Well OK, so is `conj` just `cons` with reversed argument order, or does it append to the other end of the list? My Lisp intuition tells me that the first is more likely, but the test failure doesn't show you anything, you have to use trial and error or fire up a REPL.
- cicero 14y agoThere's more to conj. It does a cons for lists, but works differently for other types of collections. You might find it helpful to lookup things in ClojureDocs. http://clojuredocs.org/clojure_core/clojure.core/conj http://clojuredocs.org/clojure_core/clojure.core/conj
- AimHere 14y agoNot really either. Conj acts on collections (which can be lists, vectors, sets or hash maps), and adds the second and subsequent arguments to the collection in a type-dependent way. For a list, your hunch is correct, in that it's a bit like a reversed-argument 'cons', except that you can have add more than one item to the list; e.g. (conj '(:a :b :c) :d :e :f) returns (:f :e :d :a :b :c)
- trptcolin 14y agoYeah, I hear you. There's definitely room for improvement here. I'm not sure what you mean by not greppable - the file is listed, as is the name of the particular koan. If there's a way to get line numbers displayed here that would be great. I agree it does make it easier to solve when you can see what you're trying to evaluate to. It was actually a conscious decision to make that not be the case, because it seemed too easy to just fill in the blanks without thinking about what should go there.
- jcoder 14y agoI have the same frustration with the Scala koans (having had my expectations set by the Ruby koans).