Article: Writing Julia style multiple dispatch code in D

data pulverizer via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Wed Aug 30 09:45:19 PDT 2017


On Monday, 28 August 2017 at 13:19:19 UTC, Jean-Louis Leroy wrote:
> On Thursday, 24 August 2017 at 23:50:21 UTC, data pulverizer 
> wrote:
>> I find OOP-polymorphic types ultimately unsatisfying, but I 
>> don't know of anyway to write, compile and load a D script 
>> with new types and methods on the fly into the same session.
>
> That is why binding membership and polymorphism together is a 
> historical wrong turn. CLOS had it right but the world followed 
> the Simula/Smalltalk path because of a nice metaphor (objects 
> sending messages to each other).
>
> My openmethods library allows you to add methods "from outside" 
> and also supports dynamic loading: you can add new methods to 
> existing classes and new classes to hierarchies that have 
> methods. See the blog post that just came up.

Thanks, just read it. Looks like a useful package. As you said it 
is about being able to dispatch with polymorphism ... where 
implicit promotions occur or explicit polymorphism is required.

One thing that confused me was examples like this ...

@method
Matrix _plus(DiagonalMatrix a, DiagonalMatrix b)
{
   // just add the elements on diagonals
   // return a DiagonalMatrix
}

Which is marked as returning a DiagonalMatrix rather than a 
Matrix by polymorphism however the function is marked Matrix 
return type.

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();

It's dispatch method is more like compile-time over as discussed 
here https://github.com/dataPulverizer/dispatch-it-like-julia - 
but you can recompile 'online' which I guess is what they mean by 
"dynamic dispatch" - but there's no polymorphism. Type 
hierarchies are basically for dispatching methods with varying 
amounts of specificity which can be accomplished using templates 
and only explicitly defined type conversions from one concrete 
type to another are allowed.



More information about the Digitalmars-d-announce mailing list