The Python Enterprise Application Kit (PEAK) is a Python framework for rapidly developing and reusing application components. While Python itself is already a very high-level language, PEAK provides even higher abstractions. One fairly recent capability added to PEAK is the capability to create generic functions and specifically to dispatch them on predicates, not simply on type. Sounds mysterious?
…even if I maybe didn’t grok everything in it. But the concept of multi-dispatch or multi-methods has always intrigued me. When I first looked at Dylan, which has an object system inspired from CLOS (Lisp), I really liked what I saw.
To me, it always seemed much more natural to separate data from methods with the ability to dispatch on mulitple arguments.
This is an extension of Python, but I’d like to see a Ruby/Python inspired scripting language make CLOS/multi-methods a central part of its core.
First of all, wasn’t that eons ago? Like months, for sure…
Also, we keep thinking: gee, when will Python finally achieve Lispiness? Or go into Smalltalk-state-of-mind ?
Predicate distpach is a really nifty feature that can generalize a lot of otherwise unconnected things (‘case’ statements, multi-method dispatch, methods on singletons, and several other things. It’s also nice for when you want to dispatch on more than just type (ie: all objects of the same type don’t behave exactly the same), but it doesn’t make sense logically to make a seperate class. A couple of other languages have this feature, notably Cecil, Goo, and an experimental version of Dylan.
There is a similar feature called predicate classes that someone convinced me was better, at least from an optimization standpoint. Consider you want to specialize a method on rectangles when width = height. You could use a predicate method for rect.width == rect.height, or, you could define a predicate class called “square”, which would inherit from rectangle and have a predicate checking for rect.width == rect.height. Then, you could use regular dispatch on that predicate class. The cool thing about predicate classes is that it integrates fairly naturally into a language with a traditional type model. Plus, since many optimization strategies (especially for dynamic languages), are based on the type system, its easier to integrate optimizations for predicate classes.
This is an extension of Python, but I’d like to see a Ruby/Python inspired scripting language make CLOS/multi-methods a central part of its core.
<a href=”http://slate.tunes.org“>Slate offers a Smalltalk-inspired syntax together with multi-methods and a very nice library.