Article: Writing Julia style multiple dispatch code in D

data pulverizer via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Wed Aug 30 10:14:37 PDT 2017


On Wednesday, 30 August 2017 at 16:45:19 UTC, data pulverizer 
wrote:
> You mentioned Julia in your article, however for clarity I 
> would point out that Julia doesn't have OOP-type polymorphism. 
> There is no notion of being able to do something like:
>
> Animal snoopy = new Dog();

p.s. my bad, I was wrong about that! Turns out you can do 
something like this in Julia (apologies for the Julia code in a D 
forum):

abstract type Animal end
struct Dog <: Animal end
struct Cat <: Animal end

x = Array{Animal}(3)
x[1] = Cat(); x[2] = Dog(); x[3] = Cat();
x # returns
3-element Array{Animal,1}:
  Cat()
  Dog()
  Cat()

Which is polymorphism


More information about the Digitalmars-d-announce mailing list