Examples of Method Combinations, Multiple Dispatch, MOP
Dear Pro, I'm currently writing a book on OOP, and after exhausting the usual stuff, I'm now at advanced topics that only Common Lisp and other Lisp dialects tackle, including Method Combinations, Multiple Dispatch and Meta-Object Protocols. Are there good motivational examples that fit in a couple of pages? And/or are there good free software or source-available programs and libraries that are worth citing and sending my readers to, to illustrate the power and interest of those techniques? For good uses the standard CLOS method combination and multiple dispatch, I am quite familiar with ASDF; and for the multiple dispatch at least, I can cite the extended version of my ELS 2014 paper. What other code bases, papers or articles may I cite? —♯ƒ • François-René ÐVB Rideau •Reflection&Cybernethics• http://fare.tunes.org “The reason truth is stranger than fiction is that fiction has to make sense.”
Dear Pro,
I'm currently writing a book on OOP, and after exhausting the usual stuff, I'm now at advanced topics that only Common Lisp and other Lisp dialects tackle, including Method Combinations, Multiple Dispatch and Meta-Object Protocols.
Are there good motivational examples that fit in a couple of pages? And/or are there good free software or source-available programs and libraries that are worth citing and sending my readers to, to illustrate the power and interest of those techniques?
For good uses the standard CLOS method combination and multiple dispatch, I am quite familiar with ASDF; and for the multiple dispatch at least, I can cite the extended version of my ELS 2014 paper. What other code bases, papers or articles may I cite?
CLIM is a good example of multiple dispatch that fits the problem domain very well. CFFI implements C-like optimizations using CLOS at compile-time. Pascal Costanza's ContextL is an interesting use of MOP. -- Stelian Ionescu
For multiple dispatch, maybe you could find examples of where people working in C++, Java, etc. have had to implement the Visitor pattern. I've done it a couple of times myself, in compilers: it's common to implement an analysis or optimization pass as a tree walk over the AST, dispatching off both the type of analysis and the type of the current AST node. Not sure that's going to be the most accessible example, though. I have used multiple dispatch in FSet. One of the nicest things about having MD available is that you don't have to think about it; if you need it, you just use it. So until this moment, I hadn't really stopped to reflect on what I use it for. For one thing, FSet has a generic function convert that has over 200 methods; it takes a symbol, which specifies a target type, and a collection to convert, dispatching on the symbol (using an eql specializer) and the type of collection. But there are various other uses too; for instance, there's a bag-sum operation which also accepts a set as either argument; this is handled in the obvious way, by dispatching on both arguments. But I don't know that either of these examples is compelling enough to use in a book. You're welcome to cite FSet, though, if you like. The only thing I've done with the MOP recently has been to write a quick-and-dirty compatibility layer <https://github.com/slburson/copycat/blob/trunk/src/defs.lisp>, allowing some old Flavors-based code to be run in Common Lisp. You're welcome to cite this as well. -- Scott On Sat, Feb 28, 2026 at 2:09 PM Faré <fahree@gmail.com> wrote:
Dear Pro,
I'm currently writing a book on OOP, and after exhausting the usual stuff, I'm now at advanced topics that only Common Lisp and other Lisp dialects tackle, including Method Combinations, Multiple Dispatch and Meta-Object Protocols.
Are there good motivational examples that fit in a couple of pages? And/or are there good free software or source-available programs and libraries that are worth citing and sending my readers to, to illustrate the power and interest of those techniques?
For good uses the standard CLOS method combination and multiple dispatch, I am quite familiar with ASDF; and for the multiple dispatch at least, I can cite the extended version of my ELS 2014 paper. What other code bases, papers or articles may I cite?
—♯ƒ • François-René ÐVB Rideau •Reflection&Cybernethics• http://fare.tunes.org “The reason truth is stranger than fiction is that fiction has to make sense.”
Hey,
I'm currently writing a book on OOP, and after exhausting the usual stuff, I'm now at advanced topics that only Common Lisp and other Lisp dialects tackle, including Method Combinations, Multiple Dispatch and Meta-Object Protocols.
out of curiosity, what do you have so far from the usual topics?
Are there good motivational examples that fit in a couple of pages? And/or are there good free software or source-available programs and libraries that are worth citing and sending my readers to, to illustrate the power and interest of those techniques?
I've made a few examples on my blog: https://turtleware.eu/posts/Method-Combinations.html -- couple of method combinations https://turtleware.eu/posts/Proxy-Generic-Function.html -- proxying function methods to another generic function https://turtleware.eu/posts/Dynamic-Vars---Return-of-the-Jedi.html -- thread-local variables ala ContextL the last one is actually used in McCLIM to a great effect, allowing for thread-safe output record history modifications. I had to incorporate some changes to make it work on LW (their MOP does not always follow the standard and closer-mop does not cover all its bases). Timothy Moore came up with a clever way to parametrize standard classes in McCLIM: https://www.jucs.org/jucs_14_20/an_implementation_of_clim/jucs_14_20_3358_33... Marco Heisig came up with a protocol for fast generic functions that allow for sealing function (sub-)domains: https://github.com/marcoheisig/fast-generic-functions That'd be all from the top of my head. Best regards, Daniel
out of curiosity, what do you have so far from the usual topics?
You can read the draft so far at http://fare.tunes.org/files/cs/poof/ltuo.html The XXX show you where I'm editing, currently at chapter 9.
Are there good motivational examples that fit in a couple of pages? And/or are there good free software or source-available programs and libraries that are worth citing and sending my readers to, to illustrate the power and interest of those techniques?
I've made a few examples on my blog: https://turtleware.eu/posts/Method-Combinations.html -- couple of method combinations https://turtleware.eu/posts/Proxy-Generic-Function.html -- proxying function methods to another generic function https://turtleware.eu/posts/Dynamic-Vars---Return-of-the-Jedi.html -- thread-local variables ala ContextL
Nice stuff, thanks. I might reference that once I discuss the MOP. Timothy Moore came up with a clever way to parametrize standard classes in
McCLIM:
https://www.jucs.org/jucs_14_20/an_implementation_of_clim/jucs_14_20_3358_33...
What are good papers to cite about CLIM in general? —♯ƒ • François-René Rideau • Chief Scientist, MuKn.com/fare “Political language is designed to make lies sound truthful and murder respectable.” — George Orwell
Coolest use of method combinations I ever saw was in celtk https://github.com/kennytilton/celtk/blob/8630194751acd7aebcb55df9b216e275d3... On Sun, 1 Mar 2026, 22:17 Faré, <fahree@gmail.com> wrote:
out of curiosity, what do you have so far from the usual topics?
You can read the draft so far at http://fare.tunes.org/files/cs/poof/ltuo.html The XXX show you where I'm editing, currently at chapter 9.
Are there good motivational examples that fit in a couple of pages? And/or are there good free software or source-available programs and libraries that are worth citing and sending my readers to, to illustrate the power and interest of those techniques?
I've made a few examples on my blog: https://turtleware.eu/posts/Method-Combinations.html -- couple of method combinations https://turtleware.eu/posts/Proxy-Generic-Function.html -- proxying function methods to another generic function https://turtleware.eu/posts/Dynamic-Vars---Return-of-the-Jedi.html -- thread-local variables ala ContextL
Nice stuff, thanks. I might reference that once I discuss the MOP.
Timothy Moore came up with a clever way to parametrize standard classes in
McCLIM:
https://www.jucs.org/jucs_14_20/an_implementation_of_clim/jucs_14_20_3358_33...
What are good papers to cite about CLIM in general?
—♯ƒ • François-René Rideau • Chief Scientist, MuKn.com/fare “Political language is designed to make lies sound truthful and murder respectable.” — George Orwell
Le 28/02/2026 23:08 CET, Faré <fahree@gmail.com> a écrit :
Are there good motivational examples that fit in a couple of pages?
Custom specializers might be worth a mention: https://research.gold.ac.uk/id/eprint/6828/1/jucs_14_20_3370_3388_newton.pdf The paper's example doesn't really show their full expressive power. You can define partial functions similar to some of what you can do with dependant types (as in Rocq/Coq or Idris). The more you lean on object-orientation (putting the data in one object rather than spread across the arguments to the generic function), the more expressive you can be. If that's interesting, you might look through the Idris book for examples, it has some good ones. Also worth noting that since the paper above was published, SKILL++ had its object system updated to include essentially all of CLOS, as well as support for custom specializers. We used them in production for a number of years. However, the code base that used them was recently simplified to make minimal use of multiple dispatch, method combinations, and custom specializers. We found using a more Smalltalk-style approach to object orientation to be beneficial to overall code quality and reliability of the system. -Thomas
participants (7)
-
Andy Chambers -
Daniel Kochmański -
Faré -
Josh -
Scott L. Burson -
Stelian Ionescu -
Thomas Burdick