What is the purpose of this function definition in Wavelets package?

#1

I like to look inside different Julia packages to get familiar with the syntax and sometimes find function definitions like this (example from Wavelets package):

function dwt end

And later on in the same file(a part of a for loop):

for (Xwt, Xwt!, _Xwt!, fw) in ((:dwt, :dwt!, :_dwt!, true),
                                (:idwt, :idwt!, :_dwt!, false))
@eval begin
    # filter
    function ($Xwt)(x::DWTArray{T}, filter::OrthoFilter,
                    L::Integer=maxtransformlevels(x)) where T<:ValueType
        y = Array{T}(undef, size(x))
        return ($_Xwt!)(y, x, filter, L, $fw)
    end

Another example from the Tracker package:

function _forward end

function track(f::F, xs...; kw...) where F
  y, back = _forward(f, xs...; kw...)
  track(Call(back, tracker.(xs)), y)
end

Can anyone please explain the purpose and how this works?

Thank you

#2

This definition only introduces the name dwt, maybe to attach a docstring to it or to define an interface to allow other packages to add methods to it.

The loop performs code generation. It defines a list of functions with similar input signature, see the relevant docs https://docs.julialang.org/en/v1/manual/metaprogramming/#Code-Generation-1

I don’t know what your question regarding the last function definition is.

#3

dwt = Discrete Wavelet Transform, it is generated code, since other function definitions are similar, they are created using metaprogramming.

Creating the blank function with no methods first is probably so that there isn’t an error in some code generation process when name is needed.

It might be that the progammer inserted the blank functions just to keep track of the naming conventions, and serves no other purpose also.