The following code may prove useful as well.

(defmacro log
  "for debugging, output code and code->val to stdout or optional
writer, returns val,
custom-fn accepts two arguments, the code, and the result, it must
return a string"
  ([code]
     `(let [c# ~code]
        (prn '~code)
        (clojure.pprint/pprint c#)
        c#))
  ([code writer custom-fn]
     `(let [c# ~code
            w# ~writer]
        (.write w#
                (~custom-fn '~code c#))
        (.flush w#)
        c#)))

(defn- add-log-calls [code]
  (if (seq? code)
    `(log ~(map add-log-calls code))
    code))

(defmacro r-log [code]
  (add-log-calls code))

The log prints the form and its output. r-log recursively wraps all
calls (symbols wrapped in parens), with the log macro. r-log stops
printing where when the form fails. Also you'll be able to see what
the passed values between functions are.
On Aug 2, 6:35 pm, recurve7 <dan.m...@gmail.com> wrote:
> Hi Jeremy,
>
> I'm not just thinking about Clojure from the perspective of a Java
> person, but also from the perspective of someone new to programming
> and for kids. For the latter, it's best if languages have maximum
> friendliness in error wording and error messages pointed at a specific
> character position on a line, which is common in many languages now.
>
> On Aug 2, 6:53 am, Jeremy Heiler <jeremyhei...@gmail.com> wrote:
>
>
>
>
>
>
>
> > 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