Is there any way to mark a symbol as obsolete in Clojure?
I could use something like this from Lein which works well.
https://github.com/technomancy/leiningen/blob/1.x/src/leiningen/core.clj#L13
But the it only emits its warning when a function is called. I'd really like the compiler to pick this up at the time code is compiled, rather than when it is called.
Of course, I could just not define the symbol, which the compiler would then pick up, but this robs me of the ability to provide any information, such as why, or when the symbol has been deprecated.
All of this is for a DSL where deprecation and obsolescence of terms is going to happen at a reasonable rate.
There's already something in the comments about using macros, but as someone noted this precludes using the function as a HOF. You can get around this, although it may be that the cure isn't worse than the disease. For example, imagine your function is
(defn foo* [x y] (+ x y))
Then instead of writing
(defmacro foo [x y] (warn) `(foo* x y))
(foo 1 2)
(map foo [5 6] [7 8])
You can make the macroexpansion return a function, which of course can be used like any other:
(defmacro foo [] (warn) `foo*)
((foo) 1 2)
(map (foo) [5 6] [7 8])
Probably not worth the awkwardness, but does provide a way to complain whenever the deprecated feature is used while still keeping the possibility of HOF usage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With