by socialdemocrat · 6y ago · 0 comments
This story is more like a general intro to Julia, but it has an example with Knights, Pikeman and Archers fighting each other (sort of rock, paper, scissors game), which also shows the utility of multiple dispatch.
https://levelup.gitconnected.com/knights-pikemen-archers-and...
But to give a quick idea here. Imagine writing functions for intersecting two geometric shapes. The algorithm for intersecting a circle and square is entirely different from intersecting a polygon and a line segment. The specific algorithm needed will depend on BOTH shapes not just one. Python can only dispatch on one of the shapes, not both.
So in Julia I could write a different function implementation like this:
intersect(c::Circle, r::Rectangle)
intersect(c1::Circle, c2::Circle)
intersect(r1::Rectangle, r2::Rectangle)
and so on.