Skip to content

Commit

Permalink
[mod] [BREAKING] Omit defn_/fn_ prefix for named fns
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Oct 30, 2024
1 parent 0492630 commit 023573d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
5 changes: 4 additions & 1 deletion src/taoensso/tufte.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,10 @@
base-id
(if ?meta-id
(enc/as-qname ?meta-id)
(str *ns* "/" (if def? "defn_" "fn_") (name fn-sym)))
(str *ns* "/"
(if ?fn-sym
(name ?fn-sym)
(str (if def? "defn_" "fn_") (name fn-sym)))))

get-ids
(if single-arity?
Expand Down
50 changes: 25 additions & 25 deletions test/taoensso/tufte_tests.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,15 @@
;;;; Util macros

(do
(tufte/defnp fn1 [x] x) ; Line 549
(tufte/defnp fn2 [x] x)
(tufte/defnp ^{:tufte/id :__fn3} fn3 [x] x)
(tufte/defnp ^{:tufte/id "__fn4"} fn4 ([x] x) ([x y] [x y]))
(tufte/defnp- fn5 [x] x)
(tufte/defnp fn1 [x] x) ; Line 549
(tufte/defnp fn2 [x] x)
(tufte/defnp ^{:tufte/id :my-fn3} fn3 [x] x)
(tufte/defnp ^{:tufte/id "my-fn4"} fn4 ([x] x) ([x y] [x y]))
(tufte/defnp- fn5 [x] x)

(defn run-test-fns []
(let [fn6 (tufte/fnp fn6 [x] x)
fn7 (tufte/fnp ^{:tufte/id :__fn7} fn7 [x] x)]
(let [fn6 (tufte/fnp fn6 [x] x)
fn7 (tufte/fnp ^{:tufte/id :my-fn7} fn7 [x] x)]
[(fn1 "fn1")
(fn2 "fn2")
(fn3 "fn3")
Expand All @@ -569,15 +569,15 @@
[(let [[r ps] (profiled {} (run-test-fns))]
[(is (= r ["fn1" "fn2" "fn3" "fn4_1" ["fn4_2x" "fn4_2y"] "fn5" "fn6" "fn7" "fn1+2"]))
(is (enc/submap? @ps
{:stats {::defn_fn1 {:n 2},
::defn_fn2 {:n 2},
:__fn3 {:n 1},
:__fn4 {:n 2}
:__fn4_1 {:n 1}
:__fn4_2 {:n 1}
::defn_fn5 {:n 1}
::fn_fn6 {:n 1}
:__fn7 {:n 1}}}))])])
{:stats {::fn1 {:n 2},
::fn2 {:n 2},
:my-fn3 {:n 1},
:my-fn4 {:n 2}
:my-fn4_1 {:n 1}
:my-fn4_2 {:n 1}
::fn5 {:n 1}
::fn6 {:n 1}
:my-fn7 {:n 1}}}))])])

;;;; Location info

Expand Down Expand Up @@ -614,15 +614,15 @@
[(is
(enc/submap? @ps
(let [nref 549]
{:stats {::defn_fn1 {:loc {:line nref}}
::defn_fn2 {:loc {:line (+ nref 1)}}
:__fn3 {:loc {:line (+ nref 2)}}
:__fn4 {:loc {:line (+ nref 3)}}
:__fn4_1 {:loc {:line (+ nref 3)}}
:__fn4_2 {:loc {:line (+ nref 3)}}
::defn_fn5 {:loc {:line (+ nref 4)}}
::fn_fn6 {:loc {:line (+ nref 7)}}
:__fn7 {:loc {:line (+ nref 8)}}}})))])])
{:stats {::fn1 {:loc {:line nref}}
::fn2 {:loc {:line (+ nref 1)}}
:my-fn3 {:loc {:line (+ nref 2)}}
:my-fn4 {:loc {:line (+ nref 3)}}
:my-fn4_1 {:loc {:line (+ nref 3)}}
:my-fn4_2 {:loc {:line (+ nref 3)}}
::fn5 {:loc {:line (+ nref 4)}}
::fn6 {:loc {:line (+ nref 7)}}
:my-fn7 {:loc {:line (+ nref 8)}}}})))])])

(comment (let [f1 (tufte/fnp foo [x] x #_(p :x x))]))

Expand Down

0 comments on commit 023573d

Please sign in to comment.