Functions with additional parentheses

I noticed this syntax in the DynamicHMCExamples package.

function (problem::LogisticRegression)(θ)
    @unpack y, X, σ = problem
    @unpack β = θ
    loglik = sum(logpdf.(Bernoulli.(logistic.(X*β)), y))
    logpri = sum(logpdf.(Ref(Normal(0, σ)), β))
    loglik + logpri

Please can someone explain what this does - I haven’t found any instances of this form of declaration elsewhere.

1 Like

It is this:

Methods are associated with types, so it is possible to make any arbitrary Julia object “callable” by adding methods to its type. (Such “callable” objects are sometimes called “functors.”)


I should probably explain things like this in the package docs, which will eventually evolve into an introduction for programming, debugging, and optimizing your own log posteriors in Julia.

Thank you both!