Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Multiple dispatch
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Julia ==== [[Julia (programming language)|Julia]] has built-in multiple dispatch, and it is central to the language design.<ref name=julia-review>{{cite journal |last1=Bezanson |first1=Jeff |last2=Edelman |first2=Alan |last3=Karpinski |first3=Stefan |last4=Shah |first4=Viral B. |title=Julia: A fresh approach to numerical computing |journal=SIAM Review |volume=59 |issue=1 |pages=65β98 |date=7 February 2017 |doi=10.1137/141000671 |arxiv=1411.1607|s2cid=13026838 }}</ref> The Julia version of the example above might look like: <syntaxhighlight lang="julia"> abstract type SpaceObject end struct Asteroid <: SpaceObject size::Int end struct Spaceship <: SpaceObject size::Int end collide_with(::Asteroid, ::Spaceship) = "a/s" collide_with(::Spaceship, ::Asteroid) = "s/a" collide_with(::Spaceship, ::Spaceship) = "s/s" collide_with(::Asteroid, ::Asteroid) = "a/a" collide(x::SpaceObject, y::SpaceObject) = (x.size > 100 && y.size > 100) ? "Big boom!" : collide_with(x, y) </syntaxhighlight> Output: <syntaxhighlight lang="julia-repl"> julia> collide(Asteroid(101), Spaceship(300)) "Big boom!" julia> collide(Asteroid(10), Spaceship(10)) "a/s" julia> collide(Spaceship(101), Spaceship(10)) "s/s" </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)