

Clojure style multimethods in python - dnene
http://codeblog.dhananjaynene.com/2010/08/clojure-style-multi-methods-in-python/

======
fogus
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:

    
    
        (defmulti say :whatiz)
        
        (defmethod say ::feline [_] (println "MEOW"))
        
        (say {:whatiz ::feline})
        ; MEOW
    

We would expect that nothing would happen if we then call it with the
following:

    
    
        (say {:whatiz ::lion})
        ; No method in multimethod 'say' for dispatch value: :user/lion
    

But we can define a hierarchy on the fly with the following:

    
    
        (derive ::lion ::feline)
    

And now we have a whimpy lion:

    
    
        (say {:whatiz ::lion})
        ; MEOW
    

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.

