How to execute code depending on julia version

@static if VERSION ≥ v"1.7"
    # do something
end

(The reason for the @static is so that this check occurs at compile time, which is sometimes important, e.g. if you want to ccall a function that doesn’t exist before a certain version then you want to strip it out before compilation.)

You should almost never have to look inside the fields of a VersionNumber (== typeof(VERSION)) object. Just do comparisons with v"..." strings as above. See also the manual on version number literals.

(I noticed that the VersionNumber docs don’t talk about comparisons, so I created a PR improving them: julia#43893.)

7 Likes