Re: Best multimethods/multiple dispatch implementations?

Raja Mukherji <rajamukherji@gmail.com>
Tue, 7 Oct 2008 01:36:50 -0700 (PDT)

          From comp.compilers

Related articles
[15 earlier articles]
Re: Best multimethods/multiple dispatch implementations? lerno@dragonascendant.com (=?ISO-8859-1?Q?Christoffer_Lern=F6?=) (2008-09-25)
Re: Best multimethods/multiple dispatch implementations? gneuner2@comcast.net (George Neuner) (2008-09-28)
Re: Best multimethods/multiple dispatch implementations? lerno@dragonascendant.com (=?ISO-8859-1?Q?Christoffer_Lern=F6?=) (2008-09-29)
Re: Best multimethods/multiple dispatch implementations? gneuner2@comcast.net (George Neuner) (2008-10-01)
Re: Best multimethods/multiple dispatch implementations? lerno@dragonascendant.com (=?ISO-8859-1?Q?Christoffer_Lern=F6?=) (2008-10-04)
Re: Best multimethods/multiple dispatch implementations? gneuner2@comcast.net (George Neuner) (2008-10-05)
Re: Best multimethods/multiple dispatch implementations? rajamukherji@gmail.com (Raja Mukherji) (2008-10-07)
| List of all articles for this month |

From: Raja Mukherji <rajamukherji@gmail.com>
Newsgroups: comp.compilers
Date: Tue, 7 Oct 2008 01:36:50 -0700 (PDT)
Organization: Compilers Central
References: 08-09-026
Keywords: OOP, code
Posted-Date: 09 Oct 2008 06:56:33 EDT

I develop my own dynamic language Wrapl (http://wrapl.sf.net) which
uses multiple dispatch for all method calls and even for infix/prefix
operations. In Wrapl multimethods dispatch on the types (or parent
types) and/or exact value (requiring identical objects, not just equal
values) of arguments. Since it is completely dynamic, all classes
(with multiple inheritance) and multimethod instances are created at
runtime, I use an extensible tree of hash tables structure and a hand-
written assembly routine for selecting the best match at runtime. It
doesn't do any caching or optimizing but still performs reasonably
well, comparable to Python's single dispatch (in a small synthetic
test, Wrapl outperformed Python by 33%).


The dispatch code uses a scoring system to find the closest match and
ambiguities may arise, e.g. should it select a method that matches
several of the arguments but doesn't use the rest or a method that
matches all the arguments but with parent types, not exact types? With
the current scoring system, the latter is chosen, but it is dependent
on the values used in the system.


If this method seems like it is of any use to you, I'd be happy to
elaborate on its workings; the source code is available from the
website but 800 lines of uncommented assembly (dispatch function and
table modification functions) may not be that helpful.


Raja



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.