@compat macro

Could someone please explain how the compat macro works from Compat.jl? I went through the source code, but it wasn’t very clear. It seems to enable defining constructors for families of types simultaneously, is that right, and is it the only way it can be used? Thanks a lot in advance.

Read the README. It’s a very complicated macro to provide compatibility to features of Julia on versions which did not includes those features, or version of Julia which had slightly different syntax. The README explains all of the cases that it currently covers.

2 Likes

So is there anything that can be done using Compat.jl but not without it in the newest versions of Julia? In other words, when developing new modules, will I ever need to use it, or is it just for the easy reuse of legacy modules?

No

Depends on what you’re developing. If you’re developing large libraries that allow users to use different versions of Julia, you need to use it in order to be able to release a version which someone on Julia v0.4 or v0.6 can use. If you’re developing libraries for yourself, you’re just getting started, or you just don’t care about supporting older versions of Julia, then you don’t need it.

4 Likes