On Fri, Jun 1, 2012 at 11:18 AM, Abraham Egnor <abe.eg...@gmail.com> wrote:
> I'm early in the process of learning clojure, and am hoping that the
> community has suggestions for a frustration I've run into.
...
> I eventually tracked it down by evaluating each subexpression of line - the
> root bug is that mul should be returning a {:dx :dy :dz} map, not a {:x :y
> :z} one, so add gets nil for the subvalues, so in turn + raises the NPE.
...
> Is there some technique I'm not seeing to make this kind of simple
> typo-based error less of a hassle to track down?  Or is this simply a matter
> of getting better at deciphering the stack traces?

I'm curious about your process for creating the solution...

Did you evolve it piece by piece in the REPL? Did you write tests for
each operation and then evolve the code until they passed? Did you
start at the top of the file and just write code until you got to the
bottom and then test the whole thing?

(obviously loaded questions - my follow-up would be that if you
started in the REPL or via a TDD-style approach, you'd have probably
caught the error earlier - but, yes, Clojure stack traces can be
pretty daunting at first)

Looking at the stack trace, the NPE comes from hex/core.clj line 8,
invoked from hex/core.clj line 42 inside the line function
(hex.core$line), during evaluation of an anonymous function (the
$fn__1022 part). That would narrow it down quite a bit and you could,
in the REPL, try (mul (delta :xy) 1) and see what you get, then (add
origin *1) ;; *1 is bound to the last result, (mul (delta :xy) 1) in
this case -- and you'd see your NPE and it should be easy to see
why... Which is why a REPL-first or test-first process would have hit
it as soon as you composed mul and add, or possibly even when you just
saw mul evaluated?

HTH... Welcome to Clojure, BTW!
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to