4 ms·
It a bit funny that the article doesn't mention Julia, which has native multimethods with all kinds of bells and whistles. It could be a nice addition to a "pol
by gajomi 10y ago
It a bit funny that the article doesn't mention Julia, which has native multimethods with all kinds of bells and whistles. It could be a nice addition to a "polyglot" flavored discussion. There is also Clojure, although its mechanism for multiple dispatch is a bit overpowered (you dispatch on values returned from a function of the arguments).
- eliben 10y agoPart 3 will talk about Common Lisp / CLOS which had multiple dispatch 20 years before Julia was conceived :-) Part 4 will talk about Clojure. I just couldn't put it all in one piece - even broken to chunks it's of formidable length
- tanlermin 10y agoWhat do you think of Julia?
- eliben 10y agoI don't think of Julia, to be honest
- StefanKarpinski 10y agoCommon Lisp has certainly had multiple dispatch for a long time. One important distinction, however, is that in CL generic functions are opt-in rather than the default. This means that most operations are not generic, limiting the extent to which you can extend things – basically only when some library author decided that you should be allowed to. Dylan and Julia both have functions which are generic by default, meaning that almost all functions can be extended. Another distinction is that while Common Lisp and Julia both have parametric types, in CL you cannot use multiple dispatch on parametric types. Since parametric types are a very useful for writing generic, reusable libraries, not being able to dispatch on them is a significant limitation. There's also the issue of performance. In Julia even something as basic as mixed-type addition – e.g. `1 + 2.5` – is defined in terms of layers of generic functions, but the compiler is clever enough to boil it down to a couple of machine instructions. This allows multiple dispatch to be used everywhere, which is really transformative. I'm not aware of any CL implementation which can eliminate the abstraction overhead of multimethods so completely. It seems a bit remiss to have a series on multiple dispatch and never mention the two languages – Dylan and Julia – that take the paradigm the furthest and most seriously.
- raiph 10y ago> Dylan and Julia both have functions which are generic by default And Perl 6. > in CL you cannot use multiple dispatch on parametric types. You can in Perl 6. > In Julia even something as basic as mixed-type addition – e.g. `1 + 2.5` – is defined in terms of layers of generic functions, but the compiler is clever enough to boil it down to a couple of machine instructions. This allows multiple dispatch to be used everywhere, which is really transformative. MD has been used everywhere in Perl 6. Perl 6 has maturity issues, including performance. But I see these as temporary issues. > It seems a bit remiss to have a series on multiple dispatch and never mention the two languages – Dylan and Julia – that take the paradigm the furthest and most seriously. Are you omitting Perl 6 because you don't think it's ready for prime time or you don't know enough about it's MD features? ------ I note that the OP series is about "runtime subtype-based polymorphism". I'm surprised at the exclusion of compile-time MD in a series which purports to be a general guide.
- StefanKarpinski 10y ago> Are you omitting Perl 6 because you don't think it's ready for prime time or you don't know enough about it's MD features? Both. Are basic operations like `+` generic in Perl 6?
- raiph 10y ago> Are basic operations like `+` generic in Perl 6? Yes.
- StefanKarpinski 10y agoWell, that's cool. Maybe Perl 6 will be the next good example of a multiple dispatch language.
- raiph 10y agoI think I misunderstood your comment about CL vs Julia/Dylan in regard to generic "by default". In Perl 6 this function definition implies a generic function: multi concatenate (\foo, \bar) { foo ~ bar } This function definition does not: sub concatenate (\foo, \bar) { foo ~ bar } If one views the latter as the "default" (because it's two characters shorter and might be learned first) then Perl 6 has the same weakness, or at least the same default, as CL, compared to Julia and Dylan.