On 12/6/2015 11:07 PM, Alexis King wrote:
More generally, I’m not sure multiple dispatch is needed, though it can be a neat tool at times. I think part of the problem is that multiple dispatch is both hard to reason about and slow to implement in a dynamically-typed language. It’s unclear what to use to dispatch on given that values do not have “types”.
I would disagree that multiple dispatch isn't needed. The Visitor pattern is used fairly frequently in real programs and it is just a overly complex, error-prone way of doing double dispatch. Trying to handle more than 2 dimensions of dispatch using Visitor involves considerable pain.
Obviously CLOS combines multiple dispatch with latent typing, so that is one place to look for solutions. How to do it most efficiently is a fair question. Various Lisps have used tables and sorting trees for multimethod dispatch. I think most implementations have settled on using tables now, but my understanding is that this was more to reduce compiler complexity than a determination that tables are more efficient in most cases.
It is true that dispatch on 3 or more arguments is rarely needed - I read somewhere that in Lisp, dispatch on 2 arguments accounts for 95+% of all multimethod use. But when it is needed, faking it on top of single dispatch is a royal PITA.
YMMV, George -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.