Thanks a lot. This way of viewing things helps.
Recently I delved into Cobweb.jl - where they have a function h
that can be used with appended dot notation - with out-of-the-box intellisense (e.g. h.div
, h.p
- etc.).
I am not saying that I am the only guy who managed to review ALL of Julia’s documentation (I certainly didn’t).
But from what I read, I never encountered the following possibility (and I am very pleased by this finding).
Now this might be something naive and not a big deal for most of the experienced Julia programmers - but for me, it was an aha moment, especially because I could do this on a function.
function myh(a)
"you called myh using property with value $a"
end
Base.getproperty(::typeof(myh), tag::Symbol) = myh(string(tag))
Base.propertynames(::typeof(myh)) = [:x, :y, :z]
myh.z # outputs: "you called myh using property with value z"
And now I can have intellisense for my myh
function (e.g. myh.x
, myh.y
).
While we have this documentation for propertynames, it wasn’t clear to me that the above feat was even possible - somewhat that doesn’t follow from the documentation (or maybe there is another relevant material that I missed).
Now, when the “unknown unknown” became “known known,” it is somehow easy to look back and give the explanation: this is the power of multiple dispatch at work. But my brain wasn’t able to travel the other way around: and this confirms what you said (these kinds of solutions have a better chance to present themselves when actually trying to achieve/solve something).
Anyway - thanks for your time and explanations.
I’ll keep up the exciting activity of reading source code - I never thought it might be so rewarding.