I am pondering on the idea of having more (or even a lot) of metadata
that could be useful for debugging and problem resolution.
Since we can store anything in metadata, can we store not only  source
file path and line number but whole source code that is associated
with piece of code?
For example, for a function we can store it's complete source code.
This way, when some piece of code throws NPE, tooling can show context
of that piece of code that caused problem (e.g. highlight it in
editor).
So, even if Clojure reader does not know actual file and line of
source code user can infer the location of code by matching structure
of code (and some tooling can do that automatically). Such information
could be especially helpful for anonymous functions.

Example:
; Source
(defn c [d]
  (#(/ % d) 13))

; REPL
(c nil)

; Ouput
NullPointerException
        clojure.lang.Numbers.ops (Numbers.java:942)
        clojure.lang.Numbers.divide (Numbers.java:154)
        petrglad.bugs/c/fn--786 (bugs.clj:17)
        petrglad.bugs/c (bugs.clj:17)
        petrglad.bugs/eval791 (NO_SOURCE_FILE:1)
        clojure.lang.Compiler.eval (Compiler.java:6465)
        clojure.lang.Compiler.eval (Compiler.java:6431)
        clojure.core/eval (core.clj:2795)
        clojure.main/repl/read-eval-print--5967 (main.clj:244)
        clojure.main/repl/fn--5972 (main.clj:265)
        clojure.main/repl (main.clj:265)
        clojure.tools.nrepl.middleware.interruptible-eval/evaluate
(interruptible_eval.clj:41)

In this case code is simple and I can guess what is happening by line
number. But what if there are more than one anonymous functions and
more operations in same line?

If source code is associated with that function it can be attached to
the exception and message could instead look like
NullPointerException in #(/ % d)
in (defn c [d] ( ... 13))
in bugs.clj line 17

I have been using Clojure occasionally for some development automation
so I could be missing something.
What do you think of this idea?

-- 
Petr Gladkikh

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