# How to interpret this function with no name, and two sets of parenthesis

**URL:** <https://discourse.julialang.org/t/how-to-interpret-this-function-with-no-name-and-two-sets-of-parenthesis/123092>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [November 26, 2024, 11:52am UTC](https://discourse.julialang.org/t/how-to-interpret-this-function-with-no-name-and-two-sets-of-parenthesis/123092 "2024-11-26T11:52:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![world-peace](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@world-peace](https://discourse.julialang.org/u/world-peace)\
**Post date:** [November 26, 2024, 11:52am UTC](https://discourse.julialang.org/t/how-to-interpret-this-function-with-no-name-and-two-sets-of-parenthesis/123092/1 "2024-11-26T11:52:33Z")

</div>

Can anyone help me understand how to interpret the below function?

It appears to be an anonymous function, but has two sets of parenthesis.

`function (j::JSON)(io, args)`

`(io, args)` are arguments to this function. But what does `(j::JSON)` mean? How should I interpret this?

```julia
function (j::JSON)(io, args)
    if j.recursive
        logmsg = to_namedtuple(Any, args; nest_kwargs=j.nest_kwargs)
        try
            JSON3.write(io, logmsg)
        catch e
            if j.nest_kwargs
                fallback_msg = to_namedtuple(String, args; nest_kwargs=true)
                fallback_msg.kwargs["LoggingFormats.FormatError"] = sprint(showerror, e)
            else
                fallback_msg = (; to_namedtuple(String, args; nest_kwargs=false)..., Symbol("LoggingFormats.FormatError") => sprint(showerror, e))
            end
            JSON3.write(io, fallback_msg)
        end
    else
        logmsg = to_namedtuple(String, args; nest_kwargs=j.nest_kwargs)
        JSON3.write(io, logmsg)
    end
    println(io)
    return nothing
end

```

This function comes from the `LoggingFormats.jl` package.

It can be found here:

- [LoggingFormats.jl/src/LoggingFormats.jl at master · JuliaLogging/LoggingFormats.jl · GitHub](https://github.com/JuliaLogging/LoggingFormats.jl/blob/master/src/LoggingFormats.jl)

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [November 26, 2024, 12:06pm UTC](https://discourse.julialang.org/t/how-to-interpret-this-function-with-no-name-and-two-sets-of-parenthesis/123092/2 "2024-11-26T12:06:37Z")

</div>

Those are methods for [function-like objects](https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects). The method table belongs to the objects’ type. In this case, `j` is a callable instance of `JSON`; that’s a name so this is not anonymous.

Typical functions are in fact also function-like objects, they just automatically get additional properties like having singleton types (no fields), a `const` name for the sole instance, subtyping `Function` for all the methods and heuristics with it, and some printing changes. You can also add methods to a typical function like `function (::typeof(foo))(args...) end`, it’s just way less convenient.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 26, 2024, 12:18pm UTC](https://discourse.julialang.org/t/how-to-interpret-this-function-with-no-name-and-two-sets-of-parenthesis/123092/3 "2024-11-26T12:18:37Z")

</div>

MWE:

```julia-repl
julia> struct A x end

julia> (a::A)(y) = y * a.x

julia> a = A(2)
A(2)

julia> a(3)
6

```

---

<div class="post-metadata">

**Author:** ![world-peace](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@world-peace](https://discourse.julialang.org/u/world-peace)\
**Post date:** [November 26, 2024, 12:40pm UTC](https://discourse.julialang.org/t/how-to-interpret-this-function-with-no-name-and-two-sets-of-parenthesis/123092/4 "2024-11-26T12:40:43Z")

</div>

Thank you both - very clear
