Is it possible to keep backwards compatibility in libraries

Is it possible to write something like this in Elixir?

-ifdef(OTP_RELEASE).
  -if(OTP_RELEASE >= 22).
    ...
  -else.
    ...
  -endif.
-else.
 ...
-endif.

Basically, what I want to do is provide two different function calls depending upon the version of OTP someone is using.

I’m getting the following warning in my library and would like to not break my OTP 23 app by upgrading the library to use only OTP 24.

:crypto.hmac/3 is undefined or private, use crypto:mac/4 instead

Here’s how plug does it: Improve check for new crypto API (#22) · elixir-plug/plug_crypto@8c1f927 · GitHub

4 Likes

Thank you!