Question about the Template type in the PkgTemplates.jl package

Hi everyone, I have a question regarding Types/Functions that came up after I discovered the PkgTemplates.jl package.

In this package I can define an object of type Template like so:

t = Template();

Then, to actually create the template, I do:

t(“PkgName”);

And I cannot understand why I can call t, which is a Type, like it is a function? I looked at the source Code, and the (I think) relevant part is this:

“”"
(::Template)(pkg::AbstractString)
Generate a package named pkg from a Template.
“”"
function (t::Template)(pkg::AbstractString)



end

Can someone explain to me what this construct does? Does it convert any Template Type into a function of the same name? I looked at the documentation for functions and types but I can’t figure it out. Why not just create a function like

createtemplate(t::Template) = ...?

Thanks in advance for any explainations!

FWIW you can also do this:

t = Template()

generate(t, "MyPackageName")

Anyway, the usage t("MyPackageName") is called a “function-like object” or “callable object”. Docs: Methods · The Julia Language

1 Like

Thanks a lot for clarifying, and pointing me to the right part of the documentation!

1 Like