In the source code for summarysize.jl
Line 63:
(ss::SummarySize)(@nospecialize obj) = _summarysize(ss, obj)
Line 88 and 89:
(::SummarySize)(obj::Symbol) = 0
(::SummarySize)(obj::SummarySize) = 0
Can someone help explain the syntax used here?
In the source code for summarysize.jl
Line 63:
(ss::SummarySize)(@nospecialize obj) = _summarysize(ss, obj)
Line 88 and 89:
(::SummarySize)(obj::Symbol) = 0
(::SummarySize)(obj::SummarySize) = 0
Can someone help explain the syntax used here?
Let’s say you have an instance s
of type SummarySize
- this function definition makes it so that using s
as a function to be called becomes possible (like s(arg)
).
(I’ve also moved this thread to “Usage”, since it’s not really a question about how the internals of julia or its design work )
@Sukera Thank you. Can you point me to the official documentation?
These are called “functors” - you’ll find many questions that mention them here on Discourse.
There’s a short section of the docs that demonstrate them here: Methods · The Julia Language
Another name for them in julia is “callable structs”, though I’m not sure there’s a seperate page of documentation available.
@EP-Guy This is really helpful. Thank you so much!