tools.trace

trace-ns traces all vars in the ns, not just fns

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    Clojure 1.5.1, tools.trace 0.7.6
  • Patch:
    Code and Test

Description

trace-ns traces every var in the given namespace, fns and non-fns alike. This is counterintuitive from the docstring (which says "trace all fns in the given name space") – when I have a data object like a map in a var, it may happen to implement IFn, but if I trace it I can't assoc onto it any more.

trace.demo> (def x {:foo 1 :bar 2})
#'trace.demo/x
trace.demo> (trace/trace-ns 'trace.demo)
nil
trace.demo> x
#<trace$trace_var_STAR_$fn__1682$tracing_wrapper__1683 clojure.tools.trace$trace_var_STAR_$fn__1682$tracing_wrapper__1683@2b0ce330>
trace.demo> (assoc x :baz 3)
ClassCastException clojure.tools.trace$trace_var_STAR_$fn__1682$tracing_wrapper__1683 cannot be cast to clojure.lang.Associative  clojure.lang.RT.assoc (RT.java:691)

I assume it's useful to retain the ability to trace IFn's that aren't fns at the level of trace-var. The attached patch instead changes trace-ns to check that traced values are fn? (not just ifn?) before wrapping them. Andy Fingerhut suggests that, if the ability to trace IFn's that aren't fns is not actually all that useful, it's simpler just to change ifn? to fn? in trace-var*.

Activity

Hide
Luc Préfontaine added a comment -

Agree. Fixed.

Show
Luc Préfontaine added a comment - Agree. Fixed.
Hide
Luc Préfontaine added a comment -

Fix accepted. Only fns are traced.

Show
Luc Préfontaine added a comment - Fix accepted. Only fns are traced.
Hide
Luc Préfontaine added a comment -

Official release 0.7.8, bad readme in 0.7.7

Show
Luc Préfontaine added a comment - Official release 0.7.8, bad readme in 0.7.7

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: