Created
April 25, 2011 10:19
-
-
Save gmarkall/940337 to your computer and use it in GitHub Desktop.
Example use of Guido's Five-minute Multimethods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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