On Tue, Aug 2, 2011 at 3:11 AM, recurve7 <dan.m...@gmail.com> wrote:
> Here's one example where recursion and lack of positional error
> feedback make it hard for me, as someone coming from Java, to spot the
> error (and seeing "ClassCastException" threw me off and had me
> wondering where/how I had done something like that):
>
> user=> (defn fac [n] (if (= n 1) 1 (* n fac (- n 1))))
> #'user/fac
> user=> (fac 3)
> java.lang.ClassCastException: user$fac cannot be cast to
> java.lang.Number (NO_SOURCE_FILE:0)
>

What were you thoughts *before* you asked Google?

As being someone who is also coming from Java, this error message
seems fairly clear. You've used `fac` when it expects a number. Now,
assuming you know how `defn` works, it must be the second instance of
`fac` that is causing the issue. Then, since it's expecting a number,
assume it is, and then ask yourself why it wouldn't complain if it was
a number. Then go from there.

Also, keep in mind you're in the REPL, where line numbers aren't all
that useful.

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