Re:Clojure style multimethods in python
by fogus on Monday August 23, 2010 @01:39PM
(#1627401)
This is very nice, but one additional aspect of Clojure's multimethods that is not mentioned is the role of ad-hoc hierarchies. That is, if we define a multimethod `say` as follows:
We would expect that nothing would happen if we then call it with the following:
But we can define a hierarchy on the fly with the following:
And now we have a whimpy lion:
This is good for simulating derived behaviors without the baggage of explicitly grouping those behaviors with the type. The multimethod dispatch and the hierarchical dispatch are completely open for extension. This is really cool.
[ Parent
| on HN ]