Fork me on GitHub
#clojure-dev
<
2022-11-18
>
Ben Sless07:11:04

Question regarding abusing the inline mechanism (sorry Alex) I want to apply inline conditionally, per namespace Possible implementation: abuse inline-arities and dynamic vars Since inline-arities is a function, I can, in theory, put any piece of code I want there, including one which inspects the environment So if I have a (inline-in-ns! foo bar) I could intern a var *inline-here*, then at inline time resolve it in the current namespace and check its value.

Ben Sless08:11:39

Another challenge is inspecting the form

Ben Sless08:11:32

Bit disgusting but it works:

(intern *ns* '*inline-here* '#{bar})

(defn foo
  {:inline (fn [x] x)
   :inline-arities (fn [n]
                     (when-let [ih (ns-resolve *ns* '*inline-here*)]
                       (when (get (deref ih) 'foo)
                         (println 'inline)
                         (= n 1))))}
  [x]
  x)