Multiple dispatch example at/for julialang.org

I think I understand multiple dispatch, but the example there is seemingly only single dispatch. People already think multiple dispatch is just the same as overloading, so which example might show it off better, and is actually multiple, as in 2+, not just one dispatch?

What kind of code might we want to show off there? I really like the syntax for e.g. polynomials.

f(x) = 2x^2 + 1

but even such simple code might put of users as too technical. I would like an example anyone can understand, general purpose, not technical computing or too mathematical. Though maybe with unitful, using the same juxtaposition trick.

[The example shown returns a set, peopke not knowing might misunderstand multiple dispatch, it’s great you have sets, and can return multiple values…]

2 Likes

Are you referring to the “greet” example on the front page of julialang.org? That one returns a tuple, not a set. (Having the two invocations of greet on separate lines might nevertheless be easier to understand.)

1 Like
function bong(x)
    return x^3
end
ulia> bong(3)
27

julia> bong("bing")
"bingbingbing"

Because bong is ducktyped, it will apply the ^ operator either to an integer or a string.