Skip to content

Instantly share code, notes, and snippets.

@gmarkall
Created April 25, 2011 10:19
Show Gist options
  • Save gmarkall/940337 to your computer and use it in GitHub Desktop.
Save gmarkall/940337 to your computer and use it in GitHub Desktop.
Example use of Guido's Five-minute Multimethods
from mm import multimethod
class Scope:
pass
class GlobalScope(Scope):
pass
class Statement:
pass
class Visitor:
@multimethod(Scope)
@multimethod(GlobalScope)
def visit(node):
print "Scope"
@multimethod(Statement)
def visit(node):
print "Statement"
v = Visitor()
scope = Scope()
globalscope = GlobalScope()
statement = Statement()
v.visit(scope)
v.visit(globalscope)
v.visit(statement)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment