Deprecated Symbols in Clojure

Is it possible to mark a character as deprecated in Clojure?

I could use something like this from Lane, which works well.

https://github.com/technomancy/leiningen/blob/1.x/src/leiningen/core.clj#L13

But it only gives a warning when a function is called. I would really like the compiler to pick this up when compiling the code, and not when it is called.

Of course, I could simply not determine the symbol that the compiler then selects, but this deprives me of the opportunity to provide any information, for example, why, or when the symbol is out of date.

All this for DSL, where obsolescence and obsolescence of conditions will occur at a reasonable rate.

+6
source share
2 answers

There is already something in the comments about using macros, but as someone pointed out, this precludes the use of the HOF function. You can get around this, although it may be that the treatment is no worse than the disease. For example, imagine your function

(defn foo* [xy] (+ xy)) 

Then instead of writing

 (defmacro foo [xy] (warn) `(foo* xy)) (foo 1 2) (map foo [5 6] [7 8]) 

You can make macro exposure a function return, which of course can be used like any other:

 (defmacro foo [] (warn) `foo*) ((foo) 1 2) (map (foo) [5 6] [7 8]) 

It’s probably not worth the awkwardness, but it makes it possible to complain whenever an outdated function is used, while still maintaining the ability to use HOF.

+1
source

It really depends on how your DSL is designed. If you can create your DSL so that each form is wrapped in go or something like that, then you could write this go macro that does something like this:

  • macroexpand-all (from clojure.walk) to completed form
  • Use postwalk (from clojure.walk) in the form above and check if any of the characters are out of date, probably by looking at some global list of obsolete characters. You may need to do resolve on characters to get the namespace character namespace.
  • If any obsolete character is found, print a message.
  • Return the input form as is.

This go macro can be used for other preprocessing of your DSL, as it is an entry point for executing DSL.

NOTE. You may have to come up with a solution in which the user uses the same name for his own character from one of the obsolete characters, but again, this may not be necessary, depending on your DSL design.

0
source

All Articles