Closed expez closed 9 years ago
can you add some examples pls?
of how inlining should work?
basically what you want to see passing as tests
Going out for a pint now; I'll add some examples when I get back. But the gist is to remove the var from the let and inline it if the var is let-bound. Remove the def
and inline if the var is defined in that manner. If the var is a function we remove the top-level defn
and replace it with an inline fn
.
Let |
indicate the cursor. Given this buffer:
(ns example.com)
(def ^:private ^:const tolerance 0.01)
(defn- calculate-frobble
[max-width]
(* max-width toler|ance))
(defn frobnicate
(let [max-width 5
frobble (calculate-frobble max-width)]
(map #(* frobble) (range 10))))
And I inline I get:
(ns example.com)
(defn- calculate-frobble
[max-width]
(* max-width 0.01))
(defn frobnicate
(let [max-width 5
frobble (calculate-frobble max-width)]
(map #(* % frob|ble) (range 10))))
And I inline again:
(ns example.com)
(defn- calculate-frobble
[max-width]
(* max-width 0.01))
(defn frobnicate
(let [max-width 5]
(map #(* % (calculate-fr|obble max-width)) (range 10))))
And I inline again:
(ns example.com)
(defn frobnicate
(let [max-width 5]
(map #(* % (* max-width 0.01)) (range 10))))
I'd like to be able to inline
A function would turn into the
fn
form and then we can consider addingcljr-demote-function
to turn anfn
into a function literal.